HTTP Status code for invalid resource specified in payload

I have a REST request (Not completely REST though). The input data is received via HTTP payload as XML and thus the record to be read is specified in the xml as,

<Item> <ID>1</ID> </Item>

Here, if the ID '1' is not found in database, should I return 404 Not found.

According to https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html, 404 Not Found is referred as The server has not found anything matching the Request-URI. But in my case, the URI can be reached successfully and the data in payload could not be found. Is it appropriate to use 404 or should I use any other status code?


First of all, why are you sending a payload to retrieve data? If you want to retrieve data in a RESTful way, you should send the id in the path, like /some-resource/1 . I hope there is a very good reason to don't follow that standard.

In any case, returning a 404 is the best approach, in my opinion. Any client would expect a 404 if the resource was not found, even when the formal definition specifies that the resource is in the URL.

链接地址: http://www.djcxy.com/p/7934.html

上一篇: REST执行失败,状态码302

下一篇: 负载中指定的无效资源的HTTP状态代码