RESTful POST 回复
RESTful POST Response
我有一个非常简单的 RESTful 服务,它通过 POST 接收一些表单数据,其目的是在云存储中简单地保留文本正文(具有唯一 ID)( Amazon S3、Azure Blob 存储等)作为文件...
所以,问题是.. 如果一切都很好,并且我 return 给调用者一个 200 响应,我应该 return 给调用者什么正文?
有什么事吗?
什么都没有?
如果这是在创建数据库记录..也许新记录的 ID 可能会有用..但在这种情况下,我认为 HttpRepsone 代码就足够了吗?
有人同意、不同意或支持link讨论吗?
我应该补充一点,对这项服务的请求非常多.. 交出,然后去.. 他们实际上 不需要 我提议的唯一 ID寄回.. 这是 "completeness".
的更多内容
简答
一旦您在服务器上创建资源,您应该return 201
status code along with a Location
header,允许客户端找到新创建的资源。
响应负载是可选的,它通常描述并链接到创建的资源。
答案有点长
请参阅 RFC 7231 中的以下引用:
[...] If one or more resources has been created on the origin server as a result of successfully processing a POST
request, the origin server SHOULD send a 201
(Created) response containing a Location
header field that provides an identifier for the primary resource created and a representation that describes the status of the request while referring to the new resource(s). [...]
也来自 RFC 7231:
The 201
(Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created. The primary resource created by the request is identified by either a Location
header field in the response or, if no Location
field is received, by the effective request URI.
The 201
response payload typically describes and links to the resource(s) created. [...]
The Location
header field is used in some responses to refer to a specific resource in relation to the response. The type of relationship is defined by the combination of request method and status code semantics.
Location = URI-reference
The field value consists of a single URI-reference. [...] For 201
(Created) responses, the Location
value refers to the primary resource created by the request. [...]
I should add that the requests to this service are pretty much.. hand off, and go.. they don't actually need the unique id
完全可以 return 不响应 post 请求。您是说来电者甚至不需要它。但是状态码 201 会更有意义。
我有一个非常简单的 RESTful 服务,它通过 POST 接收一些表单数据,其目的是在云存储中简单地保留文本正文(具有唯一 ID)( Amazon S3、Azure Blob 存储等)作为文件...
所以,问题是.. 如果一切都很好,并且我 return 给调用者一个 200 响应,我应该 return 给调用者什么正文?
有什么事吗? 什么都没有?
如果这是在创建数据库记录..也许新记录的 ID 可能会有用..但在这种情况下,我认为 HttpRepsone 代码就足够了吗?
有人同意、不同意或支持link讨论吗?
我应该补充一点,对这项服务的请求非常多.. 交出,然后去.. 他们实际上 不需要 我提议的唯一 ID寄回.. 这是 "completeness".
的更多内容简答
一旦您在服务器上创建资源,您应该return 201
status code along with a Location
header,允许客户端找到新创建的资源。
响应负载是可选的,它通常描述并链接到创建的资源。
答案有点长
请参阅 RFC 7231 中的以下引用:
[...] If one or more resources has been created on the origin server as a result of successfully processing a
POST
request, the origin server SHOULD send a201
(Created) response containing aLocation
header field that provides an identifier for the primary resource created and a representation that describes the status of the request while referring to the new resource(s). [...]
也来自 RFC 7231:
The
201
(Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created. The primary resource created by the request is identified by either aLocation
header field in the response or, if noLocation
field is received, by the effective request URI.The
201
response payload typically describes and links to the resource(s) created. [...]
The
Location
header field is used in some responses to refer to a specific resource in relation to the response. The type of relationship is defined by the combination of request method and status code semantics.Location = URI-reference
The field value consists of a single URI-reference. [...] For
201
(Created) responses, theLocation
value refers to the primary resource created by the request. [...]
I should add that the requests to this service are pretty much.. hand off, and go.. they don't actually need the unique id
完全可以 return 不响应 post 请求。您是说来电者甚至不需要它。但是状态码 201 会更有意义。