用于更新和删除的HTTP状态代码? [英] HTTP status code for update and delete?
问题描述
我应该为 UPDATE
( PUT
)和 DELETE设置什么状态代码
(例如产品是否已成功更新)?
What status code should I set for UPDATE
(PUT
) and DELETE
(e.g. product successfully updated)?
推荐答案
对于 PUT 请求: HTTP 200 或 HTTP 204 应表示资源已成功更新。
For a PUT request: HTTP 200 or HTTP 204 should imply "resource updated successfully".
对于 DELETE 请求: HTTP 200 或 HTTP 204 应表示资源已成功删除。还可以返回 HTTP 202 ,这意味着服务器已接受该指令,并且资源已被标记为删除。
For a DELETE request: HTTP 200 or HTTP 204 should imply "resource deleted successfully". HTTP 202 can also be returned which would imply that the instruction was accepted by the server and the "resource was marked for deletion".
9.6 PUT
如果现有资源被修改,则200(OK)或204(无内容)响应代码>应该发送以表示请求的成功完成。
If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes > SHOULD be sent to indicate successful completion of the request.
9.7删除
如果响应包括描述状态的实体,则响应应该为200(OK),如果操作尚未执行,则应为202(已接受);如果已执行但操作已响应,则应为204(无内容)不包括实体。
A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.
资料来源: w3.org:HTTP / 1.1方法定义
HTTP 200 OK:成功发送HTTP
请求的标准响应。实际响应将为
,具体取决于所使用的请求方法。
HTTP 200 OK: Standard response for successful HTTP requests. The actual response will depend on the request method used.
HTTP 204无内容:服务器已成功处理请求,但没有返回任何内容
HTTP 204 No Content: The server successfully processed the request, but is not returning any content
来源: HTTP状态代码列表:2xx成功
这篇关于用于更新和删除的HTTP状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!