Where Ember Data Does Not Follow JSON API

This is a heads-up for those using Ember Data. As of 1.0.0-beta.7, it doesn’t seem to conform to the following prescription of JSON API for creation of records:

“Its root key MUST be the same as the root key provided in the server’s response to GET request for the collection.” (jsonapi.org)

Also, Ember Data expects:


{
"post": {
"id": 1,
"title": "Rails is omakase",
"comments": [
"1",
"2"
],
"user": "dhh"
},
"comments": [
{
"id": "1",
"body": "Rails is unagi"
},
{
"id": "2",
"body": "Omakase O_o"
}
]
}

view raw

gistfile1.json

hosted with ❤ by GitHub

JSON API prescribes:


{
"posts": [{
"id": 1,
"title": "Rails is omakase",
"links": {
"comments": [
"1",
"2"
]
},
"user": "dhh"
}],
"linked": {
"comments": [
{
"id": "1",
"body": "Rails is unagi"
},
{
"id": "2",
"body": "Omakase O_o"
}
]
}
}

view raw

gistfile1.json

hosted with ❤ by GitHub

Update: The documentation is out of sync with the code, evidently. There seems to be support for “links” but not “linked.”

One thought on “Where Ember Data Does Not Follow JSON API

  1. I can see how Ember’s pattern is more terse and avoids nesting, both good qualities, but there is no clear indicator that post.comments[] is related to root.comments[]. The developer would have to know of the relationship in advance.

    Whereas JSON-API’s standard introduces a nested object, but makes explicit the relationship between everything in post.links and root.linked. A developer need not know which keys have relationships in advance; they need only to relate everything under ‘links’ with ‘linked’.

    Of the two examples provided, which do you prefer? In other words: would you like to see Ember Data conform to the JSON-API standard or vice versa?

Leave a comment