Subject: | Change (v2.1) to self/related links in relationships: is it really correct? |
Date: | Thu, 26 Jul 2018 14:33:00 -0400 (EDT) |
To: | Ali Zia via RT <bug-Mojolicious-Plugin-JSONAPI [...] rt.cpan.org> |
From: | Philip Spencer <pspencer [...] fields.utoronto.ca> |
Hi,
Are you sure the change you introduced in "Fix bug where the relationship
links were pointing to their origin in "related" and to their
relationships link in "self", should have been the opposite" is really
correct?
On my reading of the JSON API spec, it was correct the way it was and
wrong now.
For example, in http://jsonapi.org/format/#document-resource-object-linkage
it gives the following example:
/ ...
{
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase"
},
"relationships": {
"author": {
"links": {
"self": "http://example.com/articles/1/relationships/author",
"related": "http://example.com/articles/1/author"
},
"data": { "type": "people", "id": "9" }
}
},
"links": {
"self": "http://example.com/articles/1"
}
}
// ...
In the relationships object, the "self" link is meant to get you the
"relationship object" -- that is, the specification of the linkage between
the article and the author -- and the "related" link is meant to get you
the related resource ... that is, "http://example.com/articles/1/author"
would give you the same resource as "http://example.com/people/9".
So when building a "links document" (relationship object) in the way
illustrated in the JSON API examples, shouldn't the relationship object
have a "self" link that points to the relationship object (that is,
the URL with the word 'relationships' in it) and a "related" link that
does not have the word 'relationships' in it and points to the related
resource rather than to the links document itself?
Now I don't think the json api spec mandates what those URLs have to be,
only what they should return, so I suppose one could build an API where
$resource/relationships/$id returned the related resource and
$resource/$id returned the links document, but that would not be
consistent with the examples given in the format specification.
I think the way you had it before was consistent with the specification.
Best regards,
Philip
On Thu, 7 Jun 2018, Ali Zia via RT wrote:
Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=125504 >
>
> Thank you for the bug report, this is patched in 1.6.
>
> For some reason I was thinking length would return the number of items
> in the array :S
>
--------------------------------------------+-------------------------------
Philip Spencer pspencer@fields.utoronto.ca | Director of Computing Services
Room 167 (416)-348-9710 ext5067 | The Fields Institute for
222 College St, Toronto ON M5T 3J1 Canada | Research in Mathematical Sciences