N
N
Nice_932017-04-27 10:49:34
JavaScript
Nice_93, 2017-04-27 10:49:34

How to properly configure Adapter Ember.js and Model for received data?

Hello.
Faced such a problem there is an adapter

import DS from 'ember-data';
export default DS.RESTAdapter.extend({
  host: 'http://local:8070/api', // допустим
  headers: {
    'access-token': 'блаблаблабла'
  }
});

With api comes the following response
{
  "data": {
    "profiles": [
      {
        "id": 169,
        "slug": "Ivanov-Ivan",
        "photo": "/api/user/169/photo",
        "first_name": "ChangedFirst",
        "last_name": "ChangedLast",
        "email": "[email protected]",
        "phone": "0808956745678",
        "about": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo i",
        "tags": {
          "top": [
            "PHP",
            "JS"
          ],
          "additional": [
            "HTML",
            "CSS",
            "C++",
            "JAVA",
            "C#"
          ]
        },
        "position": null,
        "birthday": null,
        "experience_year": 0,
        "languages": null,
        "degree": "No Degree",
        "residence": null,
        "link_linkedin": null,
        "link_video": null,
        "portfolio": []
      },

calling in the route
import Ember from 'ember';

export default Ember.Route.extend({
  model(){
    return this.store.findAll('surveys')
  }
});

but nothing happens
The description is bad, I understand, maybe someone can advise what to read about setting up the adapter and how to form a model for this data. How should json be formed on the backend side? maybe the json format needs a different one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Romanov, 2017-04-27
@Kaer_Morchen

Either use JSONAPI and then everything will work out of the box, or read the RESTAdapter description , it says how the api request / response should look like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question