删除非空资源的正确HTTP错误

时间:2017-08-26 21:16:06

标签: rest api http

我使用204(无内容)来显示服务器已完成文件夹的删除请求,以及404用于无法找到文件夹的情况。如果为非空文件夹发出DELETE谓词,我想发出错误。对于这种情况,什么是正确的HTTP响应状态代码?

1 个答案:

答案 0 :(得分:0)

我相信正确的是409冲突。

The request could not be completed due to a conflict with the current state of 
the resource. This code is only allowed in situations where it is expected 
that the user might be able to resolve the conflict and resubmit the request. 
The response body SHOULD include enough information for the user to recognize 
the source of the conflict. Ideally, the response entity would include enough 
information for the user or user agent to fix the problem; however, that might 
not be possible and is not required.

http://www.restapitutorial.com/httpstatuscodes.html表示只要满足请求导致资源冲突,就应该使用409。当不支持级联删除时,重复条目和删除根对象只是一些例子。