I'm using Ember Data with a Rails API and am wondering how I can map specific actions from Ember to the API.
For example, in looking at the Ember docs for deleteRecord
and destroyRecord
I see no mention of how these methods are translated to the backend. Is this configured in the RESTAdapter.
I'd like to know which Ember methods are already wired to send specific types of requests for basic CRUD actions (e.g. destroyRecord sends a DELETE request) but also how I could build or overwrite such a method from scratch--for example, say I wanted to create a remove
method I could call on a DS.Model and have it map to /api/v1/users#destroy.
This is pretty basic and well-covered in the docs.
createRecord
followed by asave
generates a POST on/apinamespace/things
.save
on an existing record generates a PUT on/apinamespace/things/thingID
.destroyRecord
, ordeleteRecord
followed by asave
, generates a DELETE on/apinamespace/things/thingID
.The Ember Data store and model methods themselves, by design, are unaware of the details of how they are implemented at the serializer and adapter level. They merely invoke appropriate routines from the serializer and adapter. So no, one would not expect the documentation for
destroyRecord
to talk about how it's implemented in a RESTAdapter/JSONSerializer case.If you have a non-standard API scheme--let's say your DELETE method expects a URL of the form
/apinamespace/things?id=thingID
, for example--you can in some cases handle this by customizing the adapter. For instance you could overridebuildURL
. For more complex situations, you may have to back off and do your own ajax/fetch call, after which you canpush
orpushPayload
the results into the store if necessary.