且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PUT请求中的数据格式

更新时间:2023-09-11 23:20:10

假设您正在使用ember-data的默认RESTAdapter,以下是默认格式:



假设您正在更新具有以下属性的帖子:

  id:50,
标题:'PUT请求'
body:'Ember数据有很多潜力'
isPublished:false

T他将向$ c> PUT 请求:/ posts / 50。



PUT 请求将采用以下格式:

  {
post:{
id:50,
title:PUT请求,
body:Ember-data有很大的潜力,
is_published:false
}
}

RESTAdapter期望回复为与上述相同的格式。


I am preparing my server-side application to handle PUT requests comming from an emberjs client (using ember-data). The client side application is not yet ready, so that I am not able to see the real requests (this in the hands of another developer). I nevertheless want to implement the server side. Where can I find information about the detailed format of PUT requests? I need two things:

  1. What is the emberjs application going to send in the URL, headers and body of the request?
  2. What is the emberjs application expecting as reply to the the PUT request?

Here you can find a description of the REST interface which emberjs assumes, but I have been unable to find detailed information about PUT requests.

Assuming you are using ember-data's default RESTAdapter, the following is the default format:

Let's say you are updating a post with the following attributes:

id: 50,
title: 'PUT requests'
body: 'Ember-data has a lot of potential'
isPublished: false

The PUT request will be made to the URL: '/posts/50'.

the payload submitted in the PUT request will be in the following format:

{
  "post": {
    "id": 50,
    "title": "PUT requests",
    "body": "Ember-data has a lot of potential",
    "is_published": false
  }
}

The RESTAdapter expects the response to be in the same format as above.