Another option is to embed relationships in the resources themselves. This makes it easier for the customer to track the relationship between resources as they are used. For example, here is a hypothetical one personwith relations to two resources organizationthrough two resources membershipand one of these resources membership:
"person890": {
"firstName": "Jane",
"lastName": "Smith",
"links": [{
"rel": "membership",
"href": "memberships/123"
}, {
"link": "membership",
"href": "memberships/456"
}]
}
"membership123": {
"role": "chairwoman",
"date: "12/23/2013",
"term": "3 years",
"links": [{
"rel": "person",
"href": "persons/890",
}, {
"rel": "organization",
"href": "organizations/7575"
}]
}
The basic principle of work here is HATEOAS - "Hypermedia as Engine of Application State" - which allows the client with a minimal understanding of your data to still interact with your API.
sherb source
share