Post Model different than received model

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.

Thanks.

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.

1 Like

@bmac Thank you for jumping in on this after catching it on #emberjs! The Ember community once again warms the cockles of my cold, hard, heart.

Thanks for the response :). Bmac if you can share the guide for creating custom adapters that will be great. Thanks a bunch.

The guide is available here Customizing Adapters - Ember Data - Ember Guides

Prs ( https://github.com/emberjs/website/blob/master/source/guides/models/customizing-adapters.md ) and feedback welcome.

Thanks a lot Bmac :smile: