简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM