Hello,
the specification seems to be quite clear that a data JSON attribute named data
should be present in JSON response and request body.
A document MUST contain at least one of the following top-level members:
data
: the document’s “primary data”errors
: an array of error objectsmeta
: a meta object that contains non-standard meta-information.
Looking into the reference gives a couple of incomplete and seemingly complete example responses. Therefore I am a bit confused if data
should actually be always present.
Assume following example:
{
"data": {
"attributes": {
"name": "First Pool",
"description": "A good pool",
"city": "Berlin",
"country": "Germany",
"active": true
},
"id": "5c071fae-01fa-4f18-b692-7bc6fc98331f",
"links": {
"self": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f"
},
"relationships": {
"user": {
"data": {
"id": "d315dbe2-5f3a-4772-b130-7de54c5cfea5",
"type": "users"
},
"links": {
"self": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/relationships/user",
"related": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/user"
}
}
},
"type": "pools"
},
"links": {
"self": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f"
}
}
What response for /pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/relationships/user
is the correct one?
Response A
# GET /pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/relationships/user
"data": {
"id": "d315dbe2-5f3a-4772-b130-7de54c5cfea5",
"type": "users"
},
"links": {
"self": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/relationships/user",
"related": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/user"
}
Response B (Note: it could also only contain links
attribute, as data
is not mandatory)
# GET /pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/relationships/user
"data": {
"data": {
"id": "d315dbe2-5f3a-4772-b130-7de54c5cfea5",
"type": "users"
},
"links": {
"self": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/relationships/user",
"related": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/user"
}
},
"links": {
"self": "/pools/5c071fae-01fa-4f18-b692-7bc6fc98331f/relationships/user",
}
Thanks for your feedback.