如果 URL 没有改变,是否应该在 `POST` 上返回 `Location` header?
Should `Location` header be returned on `POST` if the URL didn't change?
我正在尝试确定在创建新资源及其 url 不变。
据我从文档中了解到,如果您想 return 到其他位置,则需要 Location
。
"将收件人重定向到 其他 的位置而不是 Request-URI"
14.30 Location
The Location response-header field is used to redirect the recipient
to a location other than the Request-URI for completion of the
request or identification of a new resource. For 201 (Created)
responses, the Location is that of the new resource which was created
by the request.[...]
"它的位置要么是请求的 URL,要么是位置的内容 header"
The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource. The new resource is effectively created before this response is sent back and the new resource is returned in the body of the message, its location being either the URL of the request, or the content of the Location header.
让我怀疑的是“除和”或部分
我得出的结论是无论请求 uri 是否相同,始终包含 Location
header,这样在创建资源时响应是一致的董事会。
The HTTP rfc says...
仅供参考:这已经过时了。 HTTP header 的 权威 定义(当前)通过检查 HTTP Field Name Registry 来查找字段的注册引用。
对于位置 header,当前参考是 https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-semantics#section-10.2.2
I'm trying to determine whether or not the Location header should be included as result of a POST call, when a new resource is created and the its url doesn't change.
这就是我们今天 POST 的规范:
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 (Section 10.2.2) and a representation that describes the status of the request while referring to the new resource(s).
我们也可以看看201 Created
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 header field is received, by the target URI.
因此,在创建的主要资源由目标 URI 标识的情况下,省略位置 header 与包含位置相同。
所以你有选择。我倾向于包括它 - 当一个人正在查看响应 headers 时,他们可能会被一个问题分散注意力(阅读 headers 是为了好玩),并要求人们记住针对请求的目标 URI / 交叉引用是不必要的压力。
我正在尝试确定在创建新资源及其 url 不变。
据我从文档中了解到,如果您想 return 到其他位置,则需要 Location
。
"将收件人重定向到 其他 的位置而不是 Request-URI"
14.30 Location
The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. For 201 (Created) responses, the Location is that of the new resource which was created by the request.[...]
"它的位置要么是请求的 URL,要么是位置的内容 header"
The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource. The new resource is effectively created before this response is sent back and the new resource is returned in the body of the message, its location being either the URL of the request, or the content of the Location header.
让我怀疑的是“除和”或部分
我得出的结论是无论请求 uri 是否相同,始终包含 Location
header,这样在创建资源时响应是一致的董事会。
The HTTP rfc says...
仅供参考:这已经过时了。 HTTP header 的 权威 定义(当前)通过检查 HTTP Field Name Registry 来查找字段的注册引用。
对于位置 header,当前参考是 https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-semantics#section-10.2.2
I'm trying to determine whether or not the Location header should be included as result of a POST call, when a new resource is created and the its url doesn't change.
这就是我们今天 POST 的规范:
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 (Section 10.2.2) and a representation that describes the status of the request while referring to the new resource(s).
我们也可以看看201 Created
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 header field is received, by the target URI.
因此,在创建的主要资源由目标 URI 标识的情况下,省略位置 header 与包含位置相同。
所以你有选择。我倾向于包括它 - 当一个人正在查看响应 headers 时,他们可能会被一个问题分散注意力(阅读 headers 是为了好玩),并要求人们记住针对请求的目标 URI / 交叉引用是不必要的压力。