Ramiro Jr. Franco
Ramiro Jr. Franco

Reputation: 286

How do I get / retrieve my REST data using ember-data?

I've been scouring for documentation on the REST adapter that is packaged with ember data, but I can't seem to find any information on how to actually have ember make the json request to the server, or how to retrieve or access the data once it has made the request using this adapter ( the documentation on the ember-data page seems to all be about rolling your own adapter, besides a small paragraph on how to specify if you need to disable bulk commits, though maybe I'm just missing something )

Upvotes: 4

Views: 2117

Answers (1)

pangratz
pangratz

Reputation: 16153

You have to tell your store to use the DS.RESTAdapter and this handles the communication with your server via AJAX calls, see a basic example here

You can get a basic overview how the RESTAdapter is used in the tests.

App = Ember.Application.create({});

App.store = DS.Store.create({
    revision: 3,
    adapter: DS.RESTAdapter.create({
        ajax: function(url, type, hash) {
            console.log(arguments);
        }
    })
});

App.Person = DS.Model.extend({
});

App.Person.createRecord({
});

// tell the store to contact REST service
App.store.commit();

Upvotes: 8

Related Questions