Is there a way to programmatically request the API to include the data of a set of related objects that would be passed as parameters and merge these data in the resulting tree?
There’s no extend/expand feature for the REST API. Your best possibility on this front without modifying/extending the API with a module is two requests, api/items/<id> and api/media?item_id=<id> to get all the media for that item.
Yes I know how to get the data with 2 requests. My question is about retrieving them with only one request. And of course Programmatically means for example extending the API with a module. I only need directions on where to start from.
The media in the regular output are using “reference” objects, which produce those links when serialized to JSON. You’d want to instead have the representation object for them, which will serialize to the full output. If you instead have specific data you want to include you can do that instead, of course.
Awesome, thanks John. My approach is inspired by the JSON:API concepts in their way to include resources linked to the item being requested, thus reducing the amount of code and network requests.
Note that one of most important quality of omeka is to be semantic, so rdf and json-ld, so not sure if json-api can be used. The interest of json-ld is to be structured and standard, and not to repeat everything everywhere. Anyway, you can use your own module to add anything to json, as many modules do.
So I have written a small working module that gets data for some linked resources (primary media in the example below).
You can configure the way the linked data is merged with the original tree: under the key of the linked resource (example below) or under a specific key attached to the tree root.
If you’re using the event we discussed, it should already be affecting the REST API output. Or maybe I’m not understanding what you mean when you say you want “the same functionality when requesting the REST API.”