My previous post was about attributes, good observation @emberigniter. I was unclear about exactly what “support” meant by OP, e.g. support could mean 1) hitting the rails endpoint or 2) parsing the response JSON. Both caused problems for me with the default AMS JSON API adapter.
My previous post addressed issue 2. IIUC, Serializers translate from backends to Ember Data, and handle inbound concerns. The inbound concern of the AMS JSON API response is mainly to take attributes in the response which are snake_cased and map them to the conventional camelCased attributes in the corresponding DS.Model, e.g. this response:
{
"data" : {
"type" : "resource_types",
"attributes" : {
"attr_one" : "value1",
"attr_two" : "value2"
}
...
}
}
should map to this model:
import DS from 'ember-data';
export default DS.Model.extend({
attrOne: DS.attr('string'),
attrTwo: DS.attr('string')
});
I performed that mapping in app/serializers/application.js, shown in my previous post.
To address issue 1 though, I also had to modify the application Adapter as well. Adapters translate from Ember Data to backends, and thus address outbound concerns. To be able to hit the correct endpoint on the rails server, the Ember Data model name has to be converted to camel_case and also pluralized. Ember Data would send a request to /resourceType instead of /resource_types as Rails usually expects). I did this in app/adapters/application.js:
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
pathForType: function(modelName) {
return Ember.String.pluralize(Ember.String.underscore(modelName));
},
});
It seems like a strange series of things to do because both Ember Data and ActiveModelSerializers speak JSON API. But, it’s a very small amount of code and it makes sense to have to do. They know about the structure of the JSON API response, but the specification is lax on naming conventions inside of the structure.
tl;dr Handle inbound and outbound translation concerns in Serializers and Adapters.