Question

Right now, the Ember Data RESTAdapter is making this call:

GET /workshops

I want to make this call:

POST /scripts/server/api_call.php    
{
    "http_verb": "GET",
    "endpoint": "special_namespace/workshops",
    "data": {}
}

I'm doing stuff like session management, authorization, and OAuth signing in the api_call.php script, which makes the actual RESTful request and returns the result.

What are the steps to extend the RESTAdapter to do this?

Was it helpful?

Solution

I think you'd have to override the serialize and buildURL methods. You could also override the find call directly and bypass all of the unnecessary Ember-Data calls.

But in my opinion, the RESTAdapter is incredibly complicated nowadays. Given that your API is so different, I think you would be better off writing your own adapter from scratch. My custom REST adapter is about 100 lines long, and 20 of those are just $.ajax options. For instance, your find call could be as easy as:

find: function(store, type, id) {
    return new Ember.RSVP.Promise(function(resolve) {
        var data = {
            http_verb: 'GET', 
            endpoint: 'special_namespace/' + type.typeKey.pluralize(),
            data: {}
        };

        $.post('/scripts/server/api_call.php', data, function(response) {
            resolve(response);
        });
    });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top