Adapter
A service object includes the methods from an adapter, a cache mixin. An initializer injects a specific type of serializer into the adapter. The service is an extension of an adapter and uses a mixin for a caching strategy.
The adapter methods provide an interface for the service object to interact with the backend, an API Server. The default method used to make requests is window.Fetch
. The is an option to use XHR (ajax) instead.
- See https://github.com/pixelhandler/ember-fetchjax for more info.
Define an adapter my extending the application adapter prototype.
Below is an example PostAdapter
which extends the ApplicationAdapter
:
import ApplicationAdapter from 'ember-jsonapi-resources/adapters/application';
import config from '../config/environment';
export default ApplicationAdapter.extend({
type: 'post',
url: config.APP.API_PATH + '/posts'
});
Import the application config, from ../config/environment.js
, to use a custom URL.
By default, url
is a computed property that uses config.APP.API_HOST
and config.APP.API_PATH
as the default url for the endpoint. A resource's receives and endpoint URLs, including relationships, from the JSON payload (server response).
Use the Authorization Mixin to keep track of Authorization
Header values. The adapter method fetchAuthorizationHeader
has two properties: authorizationCredential
and authorizationHeaderField
. The mixin adds the security token to the authorization header when the service makes a request.