Strongloop with Emberjs

Ember Data REST Adapter accepts JSON from the server in this format:

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 return this kind of JSON format from strongloop?

+6
source share
2 answers

Remote methods are not the best solution, because they are designed for one model and, therefore, are not DRY.

You can make Ember data compatible with Strongloop loopback api using DS.RESTAdapter with DS.JSONSerializer as follows:

 // 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 the data warehouse is stored in the adapter. The Ember Data Adapter has some built-in assumptions about what the REST API should look like. If your backend conventions are different from these assumptions, Ember Data makes it easy to change its functionality. by replacing or expanding the default adapter. "

http://guides.emberjs.com/v2.0.0/models/customizing-adapters/

Similar question: Running the Loopback API Ember.js API

+1
source

By default, closed-window api source endpoints return what looks more like:

 { "id": 1, "title": "Node is not omakase", "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" } ] } 

But you can use remote methods to do the same work, and then massage the data the way you want it to be returned. http://docs.strongloop.com/display/public/LB/Remote+methods

0
source

Source: https://habr.com/ru/post/975565/


All Articles