I know someone who is writing an API, and wants to use HTTP status codes to report the outcome of queries. e.g. if the user calls example.com/api/product_info?product_id=X
, and the product doesn't exist, it would return HTTP status 400: Bad Request
. I think that, since this is a valid call (i.e. the actual HTTP request is not malformed), it should return a 200
code response, and just have the body of the response something like {status: 'error'; message: 'No such product'}
.
So my question is,
1) Is it appropriate to use HTTP status codes to convey non-HTTP program state, as in the example above?
2) Is there some standard, or at least widely used, specification describing when HTTP status codes are appropriate for use?