Hi,
I would like to have a better understanding of the relationship link and in particular the related
field.
I have clear that the self
link regards the relationship itself but how I can use and interpret the related
link?
For what I understand the related
link could be constructed referring directly to the resource related.
An example could clear what I’m asking:
I have two resources: bands
and musicians
.
Considering that I can access to single object using bands/:id
or musicians/:id
what is the expected related
link? I present two options for a possible response to a GET bands/1
.
One
{
"links": {
"self": "http://example.com/bands/1"
},
"data": {
"type": "bands",
"id": "1",
"attributes": {
"title": "Slint"
},
"relationships": {
"guitarist": {
"links": {
"self": "/bands/1/relationships/guitarist",
"related": "http://example.com/bands/1/musicians"
},
"data": { "type": "musicians", "id": "9" }
},
"drummer": {
"links": {
"self": "/bands/1/relationships/drummer",
"related": "http://example.com/bands/1/musicians"
},
"data": { "type": "musicians", "id": "11" }
}
}
}
}
Two
{
"links": {
"self": "http://example.com/bands/1"
},
"data": {
"type": "bands",
"id": "1",
"attributes": {
"title": "Slint"
},
"relationships": {
"guitarist": {
"links": {
"self": "/bands/1/relationships/guitarist",
"related": "http://example.com/musicians"
},
"data": { "type": "musicians", "id": "9" }
},
"drummer": {
"links": {
"self": "/bands/1/relationships/drummer",
"related": "http://example.com/musicians"
},
"data": { "type": "musicians", "id": "11" }
}
}
}
}
Thank you for the eventual reply!