Ember 使用 Restadapter 和 Jsonapiadapter 作为适配器。 就请求/响应的数据格式而言,两者之间的确切区别是什么? 使用这两个中的任何一个时我们需要确保的任何其他事情。
最佳答案
使用RESTAdapter当您有一个 JSON API,该 API 遵循具有复数对象名称的 REST 端点,并且具有使用返回的对象名称的根节点。
下面的例子:
JSONAPI 规范对象示例:
{
"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"
}
}]
}
示例 Rest json api 对象:
{
"posts": {
"id": 5,
"title": "An API that gets bikeshed for months ",
"author": "kiwiupover",
"comments": [1]
},
"comments": [{
"id": 1,
"name": "Dave",
}]
}
Ember Data 提供了使 DS.adapter 适应特定 JSON API 形状的简单方法。
还有第三个adapter前面提到的适配器是从中扩展而来的。
关于javascript - Ember Restadapter 与 Jsonapiadapter 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52490540/