简体   繁体   中英

Ember Difference between Restadapter vs Jsonapiadapter

Ember uses Restadapter & Jsonapiadapter for the adapters. What are the exact differences between the 2 in terms of data formats for request/response ? Any other things we need to ensure when using any of these 2.

The JSONAPIAdapter conforms to the JSONApi spec

Use RESTAdapter when you have an JSON API that follows a REST endpoint with pluralized object names and has a root node using the name of the object being returned.

Examples below:

Example JSONAPI spec object:

{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!"
    },
    "relationships": {
      "author": {
        "links": {
          "self": "http://example.com/articles/1/relationships/author",
          "related": "http://example.com/articles/1/author"
        },
        "data": { "type": "people", "id": "7" }
      }
    },
  }],
  "included": [{
    "type": "people",
    "id": "7",
    "attributes": {
      "name": "Dave",
      "twitter": "kiwiupover"
    }
  }]
} 

Example Rest json api object:

{
  "posts": {
    "id": 5,
    "title": "An API that gets bikeshed for months ",
    "author": "kiwiupover",
    "comments": [1]
  },
  "comments": [{
    "id": 1,
    "name": "Dave",
  }]
}

Ember Data provides straightforward methods for adapting your DS.adapter to your specific JSON API shape.

There is a third adapter from which the previously mentioned adapters are extended from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM