Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strongloop with Emberjs

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?

like image 226
user3568719 Avatar asked Apr 25 '15 09:04

user3568719


1 Answers

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

like image 114
Robert Carter Mills Avatar answered Oct 11 '22 01:10

Robert Carter Mills