Adapt to a Nonconventional API

As built so far, the EmberNote API has used the conventions Ember Data expects from an API. However, not every API you encounter will follow these conventions. Let’s look at how to make Ember Data fit such an API.

Adding Request Headers to Your API

We’ll start by exploring how to use additional API features by modifying JSONAPIAdapter as follows:

 import​ DS from ​'ember-data'​;
 
 export​ ​default​ DS.JSONAPIAdapter.extend({
  headers: ​function​() {
 if​(​this​.get(​'session.user'​)) {
 return​ {
 'username'​ : ​this​.get(​'session.user'​).get(​'name'​)
  };
  }
  }.property(​'session.user'​)
 });

This simple change allows you to add request headers to your ...

Get Deliver Audacious Web Apps with Ember 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.