Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 )

like image 568
Ramiro Jr. Franco Avatar asked Feb 22 '23 01:02

Ramiro Jr. Franco


1 Answers

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();

like image 140
pangratz Avatar answered Mar 03 '23 18:03

pangratz