我应该 return 来自 HTTP DELETE 端点的响应状态代码是什么?
What response status codes should I return from an HTTP DELETE endpoint?
在以下情况下,我应该从 HTTP DELETE 端点 return 什么响应状态代码:
- 当资源存在时(我相信是 200)
- 当资源不存在时(应该是200还是404,还是smth?)
换句话说,我应该将删除不存在的资源的尝试视为错误,还是应该用 OK 来响应?
好的,there’s always an answer in the RFCs:
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.
在以下情况下,我应该从 HTTP DELETE 端点 return 什么响应状态代码:
- 当资源存在时(我相信是 200)
- 当资源不存在时(应该是200还是404,还是smth?)
换句话说,我应该将删除不存在的资源的尝试视为错误,还是应该用 OK 来响应?
好的,there’s always an answer in the RFCs:
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.