更新和删除的 HTTP 状态码? [英] HTTP status code for update and delete?

查看:100
本文介绍了更新和删除的 HTTP 状态码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该为UPDATE(PUT)和DELETE(例如产品成功更新)设置什么状态码?

解决方案

对于 PUT 请求:HTTP 200HTTP 204 应该暗示资源更新成功".

对于 DELETE 请求:HTTP 200HTTP 204 应该暗示资源删除成功".HTTP 202 也可以返回,这意味着该指令已被服务器接受并且资源已标记为删除".

<块引用>

PUT

如果现有资源被修改,则应发送 200(OK)或 204(无内容)响应代码以指示请求成功完成.

<块引用>

删除

如果响应包含描述状态的实体,则成功响应应该是 200(OK),如果操作尚未执行,则为 202(已接受),如果操作已执行但响应为 204(无内容)不包括实体.

来源:W3.org:HTTP/1.1 方法定义

<块引用>

HTTP 200 OK:成功 HTTP 的标准响应要求.实际反应将取决于所使用的请求方法.

HTTP 204 No Content:服务器成功处理了请求,但没有返回任何内容

来源:HTTP 状态代码列表:2xx 成功

What status code should I set for UPDATE (PUT) and DELETE (e.g. product successfully updated)?

解决方案

For a PUT request: HTTP 200 or HTTP 204 should imply "resource updated successfully".

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".

PUT

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.

DELETE

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.

Source: W3.org: HTTP/1.1 Method Definitions

HTTP 200 OK: Standard response for successful HTTP requests. The actual response will depend on the request method used.

HTTP 204 No Content: The server successfully processed the request, but is not returning any content

Source: List of HTTP status codes: 2xx Success

这篇关于更新和删除的 HTTP 状态码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆