Class DS.Adapter

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.