Class DS.Adapter

Extends: Ember.Object
Defined in: addon/adapter.js:7
Module: ember-data

An adapter is an object that receives requests from a store and translates them into the appropriate action to take against your persistence layer. The persistence layer is usually an HTTP API, but may be anything, such as the browser's local storage. Typically the adapter is not invoked directly instead its functionality is accessed through the store.

Creating an Adapter

Create a new subclass of DS.Adapter in the app/adapters folder:

app/adapters/application.js
1
2
3
4
5
import DS from 'ember-data';

export default DS.Adapter.extend({
  // ...your code here
});

Model-specific adapters can be created by putting your adapter class in an app/adapters/ + model-name + .js file of the application.

app/adapters/post.js
1
2
3
4
5
import DS from 'ember-data';

export default DS.Adapter.extend({
  // ...Post-specific adapter code goes here
});

DS.Adapter is an abstract base class that you should override in your application to customize it for your backend. The minimum set of methods that you should implement is:

  • findRecord()
  • createRecord()
  • updateRecord()
  • deleteRecord()
  • findAll()
  • query()

To improve the network performance of your application, you can optimize your adapter by overriding these lower-level methods:

  • findMany()

For an example implementation, see DS.RESTAdapter, the included REST adapter.

Show:

By default the store will try to coalesce all fetchRecord calls within the same runloop into as few requests as possible by calling groupRecordsForFindMany and passing it into a findMany call. You can opt out of this behaviour by either not implementing the findMany hook or by setting coalesceFindRequests to false.

If you would like your adapter to use a custom serializer you can set the defaultSerializer property to be the name of the custom serializer.

Note the defaultSerializer serializer has a lower priority than a model specific serializer (i.e. PostSerializer) or the application serializer.

app/adapters/django.js
1
2
3
4
5
import DS from 'ember-data';

export default DS.Adapter.extend({
  defaultSerializer: 'django'
});