Our team is developing RESTFul applications...we are debating the "BEST PRACTICE" approach.
Should 404 status code response be returned for a filter-like query? Say my GET URL is
.../1/service/startsWith/a.json
and it returns all values that start with A in my database...but if no "a" values are found should i just return status code 200 with an empty json string? or status code 404.
Thanks!
See this question, in the update to my answer I address your issue. Specifically this bit,
I think the answer to whether to return 404 depends on the what is the resource that is being retrieved. Is it a representation of a search result, or is it a representation of a product? To know this you really need to look at the link relation that led us to the URL.
If the URL is supposed to return a Product representation then a 404 should be returned if the code does not exist. If the URL returns a search result then it shouldn't return a 404.
The end result is that what the URL looks like is not the determining factor. Having said that, it is convention that query strings are used to return search results so it is more intuitive to use that style of URL when you don't want to return 404s.
It may be more sensible to return a 204 code, which means 'No Content'. This would be slightly more efficient as a 204 status cannot have any document content, plus you can detect the code instead of having to parse the response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With