【问题标题】:What is the complete list of expected JSON responses for DS.RESTAdapter?DS.RESTAdapter 的预期 JSON 响应的完整列表是什么?
【发布时间】:2013-02-02 01:49:45
【问题描述】:

我正在尝试为 Ember.js 应用程序编写基于 express.js 的自定义服务器。我相处得很好,但我总是被困在试图猜测 Ember Data 在给定时刻期望什么 JSON 响应。

这个全新的文档是一个很好的开始http://emberjs.com/guides/models/the-rest-adapter/,但还不够完整。

我在黑暗中的刺伤让我明白了(Ember pre4,Ember Data 11):

Context                                Server URL          Method     Req. Data                  Resp. Data
~~~~~~~                                ~~~~~~~~~~          ~~~~~~     ~~~~~~~~~                  ~~~~~~~~~~
Getting a list of all users            /users              GET                                   {"users":[{...},{...}]}
Getting a particular user              /users/123          GET                                   {"user":{...}}
Creating a user                        /users              POST       {"user":{...}}             ???
Updating a user                        /users/123          PUT        {"user":{...}}             ???
Deleting a user                        /users/123          DELETE     ???                        ???

Creating a user (bulkUpdate)           /users              POST       {"users":[{...},{...}]}    ???
Updating a user (bulkUpdate)           /users/bulk         PUT        {"users":[{...},{...}]}    ???
Deleting a user (bulkUpdate)           /users/123          DELETE     ???                        ???

有人可以帮我填写其中的一些空白吗?

编辑,预期 JSON 响应的完整列表

这些响应是从ember-data REST adapter unit tests 和通过观察Example Ember Data app 上的网络流量收集的。

Context                                Server URL          Method     Req. Data                  Resp. Data
~~~~~~~                                ~~~~~~~~~~          ~~~~~~     ~~~~~~~~~                  ~~~~~~~~~~
Getting a list of all users            /users              GET                                   {"users":[{...},{...}]}
Getting a particular user              /users/123          GET                                   {"user":{...}}
Creating a user                        /users              POST       {"user":{...}}             {"user":{...}}
Updating a user                        /users/123          PUT        {"user":{...}}             {"user":{...}}
Deleting a user                        /users/123          DELETE     N/A                        null

Creating a user (bulkCommit)           /users              POST       {"users":[{...},{...}]}    {"users":[{...},{...}]}
Updating a user (bulkCommit)           /users/bulk         PUT        {"users":[{...},{...}]}    {"users":[{...},{...}]}
Deleting a user (bulkCommit)           /users/bulk         DELETE     {"users":[1,2]}            {"users":[1,2]}

【问题讨论】:

标签: ember.js ember-data ember-router


【解决方案1】:

与其在黑暗中刺伤,不如看看rest-adapter-test

例如,要填写关于批量更新的响应数据的问题,L738 描述了预期的响应数据:

ajaxHash.success({ people: [
  { id: 1, name: "Brohuda Brokatz" },
  { id: 2, name: "Brocarl Brolerche" }
]});

【讨论】:

【解决方案2】:

目前在 rest-adapter-test.js 源中查找短语 ajaxResponse( 嵌套在 test("create - a payload with a new ID and data applies the updates" 看起来相似的块中以读取服务器的所需响应。

【讨论】:

    猜你喜欢
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 2021-03-04
    • 2014-02-25
    • 1970-01-01
    • 2016-06-03
    相关资源
    最近更新 更多