When is RESOURCE NOT FOUND (404) appropriate?

httpresponse, rest, url

Solution

This is definitely still a 404. Don't look at urls as a long list of parameters, but instead look at the url as a whole identifier. In your particular example the identifier doesn't point to anything, but it's not an invalid url.

404 is the most appropriate here.

Problem

I have been having long discussion with colleagues about whether responing with a 404 or 400 (BAD REQUEST) given different bad parts of the url. Suppose we have a endpoint that provides products. But the products are segmented and depend on things like country, channel (like a b2b or b2c), etc. In an url like /myapi/v1/{country}/{channel}/products/{product-id} it is quite clear for me to respond RESOURCE NOT FOUND if the caller gave me a bad "product-id". But what about "country"? I would argue that "country" is not the resource supplied by the current url, so the response (in the case where the "country" provided is bad) should be BAD REQUEST. Other people are arguing that the whole url is like the signature of the resource and a bad "country" will result failure to return a 200, thus RESOURCE NOT FOUND should be the response status. Which one is the correct status? And what is correct question to ask?

Original source