1

In the JSONAPI specification, under Resource Objects it gives this example of a resource:

{
  "type": "articles",
  "id": "1",
  "attributes": {
    "title": "Rails is Omakase"
  },
  "relationships": {
    "author": {
      "links": {
        "self": "/articles/1/relationships/author",
        "related": "/articles/1/author"
      },
      "data": { "type": "people", "id": "9" }
    }
  }
}

If I'm NOT using resource inclusion, what should my client be doing with the information contained in:

"data": { "type": "people", "id", "9" }

The response includes a link to the article's author (/articles/1/author) - and I can tell from reading the data { ... } element of the response that the author of this article is the person with id=9, but I can't actually do anything useful with that information.

It would seem intuitive that I could use this information to make a GET request to /people/9 to retrieve author details, but that doesn't appear to be part of the JSONAPI spec (although there is a recommendation along these lines regarding URLs for resource collections)

Is the inline type/id information only relevant in the context of either resource inclusion or cross-referencing with some previously cached response data? Or is there an undocumented convention about translating type+id into a resource URL (GET /{type}/{id}) ?

Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197

1 Answers1

0

It's there for cross-referencing other data retrieved from the server. You may load the record person:9 incidentally at some other time, and knowing the author relationship on article:1 would save you the trouble of sending a GET to /articles/1/relationships/author.

The ember-data client-side store, for instance, resolves the reference for you automatically.

andorov
  • 4,197
  • 3
  • 39
  • 52