Search code examples
ember-data

JSONAPIAdapter - Use camel case instead of dasherized case


Is there a quick and easy way to use camel case when serializing a JsonApi model? By default is is using dasherized case for both url and field names.


Solution

  • Look at EmberJS guides for an example how to make user-profile-related adapter hit user_profile instead:

    export default DS.JSONAPIAdapter.extend({
      pathForType: function(type) {
          return Ember.String.underscore(type);
      }
    });
    

    Requests for person would now target /person/1. Requests for user-profile would now target /user_profile/1

    If you need to serialize attributes, not just the model names, you can find related section to the topic at the very same place, direct link here.

    Since the example above uses Ember.String.underscore(), I am attaching a link to very useful String helpers Ember provides by default, Ember.String API: