我应该为UPDATE(PUT)和DELETE(例如产品成功更新)设置什么状态码?
解决方案对于 PUT 请求:HTTP 200 或 HTTP 204 应该暗示资源更新成功".
对于 DELETE 请求:HTTP 200 或 HTTP 204 应该暗示资源删除成功".HTTP 202 也可以返回,这意味着该指令已被服务器接受并且资源已标记为删除".
PUT
如果现有资源被修改,则应发送 200(OK)或 204(无内容)响应代码以指示请求成功完成.
删除
如果响应包含描述状态的实体,则成功响应应该是 200(OK),如果操作尚未执行,则为 202(已接受),如果操作已执行但响应为 204(无内容)不包括实体.
来源:W3: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: 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 状态码?
发布评论