Hello,
let’s say we have an event resource that is linked to a location resource. This location resource is linked to another location, and this one to a third and so on.
I want to request the event and the data for the whole location resource hierarchy.
First question
How do I request the document (example below)?
- http://example.com/events/1?include=location
(because “location” is also used in the included resources) - http://example.com/events/1?include=location,location.location
(to explicitly say, that I want to include the locations of locations) - http://example.com/events/1?include=location,location.location,location.location.location,location.location.location.location[...]
(would be really bad, because the client doesn’t know the number of levels)
Second question
How to control if all hierarchies are returned or not (if variant 1 or 2 solves this)? Perhaps the client only wants the top level.
Example
{
“data”: {
“type”: “event”,
“id”: “1”,
“attributes”: {
“title”: “My event”
},
“links”: {
“self”: “http://example.com/events/1”
},
“relationships”: {
“organizer”: {
“links”: {
“self”: “http://example.com/events/1/relation-organizer”,
“related”: “http://example.com/events/1/organizer”
},
“data”: { “type”: “users”, “id”: “2” }
},
“location”: {
“links”: {
“self”: “http://example.com/events/1/relation-location”,
“related”: “http://example.com/events/1/location”
},
“data”: { “type”: “locations”, “id”: “99” }
}
}
},
“included”: [{
“type”: “locations”,
“id”: “99”,
“attributes”: {“name”: “Name of the Building”},
“relationships”: {
“location”: {“data”: { “type”: “locations”, “id”: “98” }}
},
“links”: {“self”: “http://example.com/locations/99”}
}, {
“type”: “locations”,
“id”: “98”,
“attributes”: {“name”: “Name of the Street”},
“relationships”: {
“location”: {“data”: { “type”: “locations”, “id”: “97” }}
},
“links”: {“self”: “http://example.com/locations/98”}
}, {
“type”: “locations”,
“id”: “97”,
“attributes”: {“name”: “Name of the City”},
“relationships”: {
“location”: {“data”: { “type”: “locations”, “id”: “96” }}
},
“links”: {“self”: “http://example.com/locations/97”}
}, {
“type”: “locations”,
“id”: “96”,
“attributes”: {“name”: “Name of the Country”},
“relationships”: {
“location”: {“data”: { “type”: “locations”, “id”: “95” }}
},
“links”: {“self”: “http://example.com/locations/96”}
}, {
“type”: “locations”,
“id”: “95”,
“attributes”: {“name”: “Name of the Continent”},
“relationships”: {
“location”: {“data”: { “type”: “locations”, “id”: “94” }}
},
“links”: {“self”: “http://example.com/locations/95”}
}, {
“type”: “locations”,
“id”: “94”,
“attributes”: {“name”: “World”},
“links”: {“self”: “http://example.com/locations/94”}
}]
}
Thanks,
Christoph