How to implement a REST API in Drupal for nested field collections

Viewed 433

I am trying to put together a headless Drupal 7 implementation around a content type with repeated nested data. I have no option but to use Drupal 7 vs Drupal 8 or a native headless CMS.

For example, consider a music album which could be modeled as an Album resource as:

{"title" : "Something Cool",
 "tracks" : [
    "track" : {
      "title": "Track 1", 
      "samples" : [
        {"file" : "/path/to/file"},
        {"file" : "/path/to/another/file"}
      ]
   }
 ]
}

In D7, I can define a content type using some nested field collections to represent the repeating structures in the above and the Services module to expose that as a REST endpoint. The problem I have is that the Services api doesn't traverse into the field collection so I would be left with just a top level property for the tracks and no detail.

Is there a simple way to implement this using an alternate REST module or Services. I have seen one post that implemented a separate lookup for the field collection which is not ideal since that would result in several roundtrips for each

1 Answers
Related