Strongloop with Emberjs
Asked Answered
E

2

6

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?

Esquivel answered 25/4, 2015 at 9:15 Comment(0)
S
1

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

Sostenuto answered 10/9, 2015 at 4:29 Comment(0)
G
0

By default the out-of-box restful api endpoints would return something that 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 into the way you want it to be returned. http://docs.strongloop.com/display/public/LB/Remote+methods

Godly answered 26/4, 2015 at 3:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.