Contents
When to return success if a result is not found?
If the client expects exactly one result, then return success if the result is found, and an error if the result is not found. Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question.
When to use ” no results ” in a restful response?
If the query is the kind that looks up and returns a specific singleton (that is expected to be found, e.g. exact match by id), then not found is a logically appropriate possible response. You’re assuming the code has to take a special action when there is no data returned, but that might not be the case.
When to return a status 404 with no value?
Here it is much more acceptable to return a status 404 for the case that no value is there, because I do need to handle that case differently anyway. Summary: If the client expects any number of results, from zero to large numbers, then return “success” if all results are delivered, even if the number is zero.
Is it wrong to respond with no message body?
204 isn’t semantically wrong here, but you would have to respond with no message body whatsoever. This means all client code would have to explicitly check for different HTTP codes (or at least for the lack of a message body) and handle them separately. It’s inconvenient and more likely to lead to poorly behaved clients.
How to return a value with no records?
Looking for the simplest method to account for no records. This is similar to Adam Robinson’s, but uses ISNULL instead of COUNT. If the inner query has a matching row, then 1 is returned. The outer query (with ISNULL) then returns this value of 1.
When to return success or error in rest?
Summary: If the client expects any number of results, from zero to large numbers, then return “success” if all results are delivered, even if the number is zero. If the client expects exactly one result, then return success if the result is found, and an error if the result is not found.