Caveat: I’m new to “proper” RESTful design, so this question may be naive:
In the example, GETting “/articles/1” we see the response:
> {
> "data": [{
> "type": "articles",
> "id": "1",
> "attributes": {
> "title": "JSON API paints my bikeshed!"
> },
> "links": {
> "self": "http://example.com/articles/1"
> },
> "relationships": {
> "author": {
> "links": {
> "self": "http://example.com/articles/1/relationships/author",
> "related": "http://example.com/articles/1/author"
> },
> "data": { "type": "people", "id": "9" }
> },
> "comments": {
> "links": {
> "self": "http://example.com/articles/1/relationships/comments",
> "related": "http://example.com/articles/1/comments"
> },
> "data": [
> { "type": "comments", "id": "5" },
> { "type": "comments", "id": "12" }
> ]
> }
> }
> }],
> "included": [{
…
> }]
> }
For this question, let’s ignore the “included” section (as in the case where “included=” is not part of the query). This means, I believe, that to fetch just one of the comment resources directly, e.g. ({ “type”: “comments”, “id”: “12” }), you would either
(A) concatenate the “type” and “id” from the relationships.comments.data[0] item and issue a “GET /comments/12”
or
(b) concatenate the URI from releationships.comments.links.related and the relationships.comments/data[0].id and issue “GET /articles/1/comment/12”
Is one of those incorrect, are are both options available?
And, perhaps more to the meat of my question: Isn’t constructing a URL like this non-RESTful? It seems more RESTful (if more wordy) to include the exact URL in the relationships section, e.g. I’m proposing:
> "comments": {
> "links": {
> "self": "http://example.com/articles/1/relationships/comments",
> "related": [
> "http://example.com/articles/1/comments/5",
> "http://example.com/articles/1/comments/12"
> ]
> }
Thanks in advance for feedback / comments,
Mark