Ember Data 2.4 with new JSON:API specification


#1

Trying to call an API that is returning me JSON. I am getting the following error

Error while processing route: treatment Assertion Failed: normalizeResponse must return a valid JSON API document:
	* One or more of the following keys must be present: "data", "errors", "meta". Error: Assertion Failed: normalizeResponse must return a valid JSON API document:
	* One or more of the following keys must be present: "data", "errors", "meta".

Is there a way in Ember to get around this or do I need to have the API team change the way the JSON response is coming back? Thanks


#2

You can change your application adapter to expect REST instead:

DS.RESTAdapter

If not, you’ll have to stick with JSON API. You can read http://jsonapi.org/ to learn more.


#3

So I changed adapters/application.js to the following:

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  namespace: 'Service.svc'
});

I am still getting the same error


#4

That’s weird. We’re using the latest Ember and Ember Data in a project using REST without any trouble, and those error’s clearly point to the JSON not being conform JSON API.


#5

Can you post what the server response looks like when you hit the API directly?


#6

Here is a sample

{
  "ArgumentErrors": null,
  "ErrorCode": 0,
  "ErrorMessage": null,
  "IsSuccess": true,
  "Services": [
     {
        "AllowCustomers": true,
        "Name": "John Smith Service"
     },
    {
        "AllowCustomers": false,
        "Name": "John Apples Service"
    }
  ]
}

#7

Do you have any Model specific Adapters defined (and its type JSONAPIAdapter) ???


#8

Does that fit the format the REST adapter expects as described here?


#9

So I had to serialize the return coming in the API after switching to a REST adapter. Thanks