48

我正在尝试为 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 适配器单元测试和通过查看Example Ember Data 应用程序上的网络流量收集的。

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]}
4

2 回答 2

25

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

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

ajaxHash.success({ people: [
  { id: 1, name: "Brohuda Brokatz" },
  { id: 2, name: "Brocarl Brolerche" }
]});
于 2013-02-18T21:17:54.103 回答
0

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

于 2015-08-21T11:58:25.343 回答