Hi,
I have a requirement where in I have a REST API (Not controlled by me) which needs some JSON data in a specific format as a Post request and returns a JSON response in a different format. My question is, can Ember data be used here? Can I write custom Adapter which modifies the request when we make a find query I can modify the request from ‘get’ to ‘post’ and add the post data and in turn get the data using custom serializer.
Hello @batman. Yes you can do this by creating a custom adapter. You may want to look at the Adapter - 4.6 - Ember API Documentation documentation but it sounds like you will want to create a custom find method for your adapter. This could be something as simple as
App.ApplicationAdapter = DS.RESTAdapter.extend({
find: function(store, type, id) {
var data = {
id: id,
// other JSON data here
};
return this.ajax(this.buildURL(type.typeKey, id), 'POST', data);
}
});
Please let me know if you run into any trouble creating a custom adapter. I’m working on putting together a guide to cover custom adapters atm.