Ember Data's REST Adapter accepts the JSON from the server in this format:
Taken from the documentation: http://guides.emberjs.com/v1.10.0/models/the-rest-adapter/
{
"post": {
"id": 1,
"title": "Node is not omakase",
"comments": [1, 2, 3]
},
"comments": [{
"id": 1,
"body": "But is it _lightweight_ omakase?"
},
{
"id": 2,
"body": "I for one welcome our new omakase overlords"
},
{
"id": 3,
"body": "Put me on the fast track to a delicious dinner"
}]
}
Is it possible to have this kind of JSON format back from strongloop?
Remote methods are not the best solution because they are per model, and thus not DRY.
You can make Ember-data compatible with Strongloop's loopback api by using the DS.RESTAdapter
with DS.JSONSerializer
like this:
// app/adapters/application.js
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: 'http://loopback-api-host',
namespace: 'api',
defaultSerializer: 'JSONSerializer'
});
http://emberjs.com/api/data/classes/DS.JSONSerializer.html
"In Ember Data, the logic for communicating with a backend data store lives in the Adapter. Ember Data's Adapter has some built-in assumptions of how a REST API should look. If your backend conventions differ from these assumptions Ember Data makes it easy to change its functionality by swapping out or extending the default Adapter."
http://guides.emberjs.com/v2.0.0/models/customizing-adapters/
Similar question: Making Loopback API Ember.js compatible
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With