我正在尝试为Ember.js应用程序编写一个基于custom.js的自定义服务器。我相处得很好,但是我一直在试图猜测Ember Data在特定时刻的反应是什么。
这个全新的文档是一个很好的开始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]}
答案 0 :(得分:24)
不要在黑暗中刺伤,而是看看rest-adapter-test
例如,要填写有关批量更新的响应数据的问题,L738描述了预期的响应数据:
ajaxHash.success({ people: [
{ id: 1, name: "Brohuda Brokatz" },
{ id: 2, name: "Brocarl Brolerche" }
]});
答案 1 :(得分:0)
目前在ajaxResponse(
嵌套在rest-adapter-test.js
外观块中的test("create - a payload with a new ID and data applies the updates"
源代码中查找短语setImageResolution
,以便阅读服务器所需的响应。