I wanted to know how I should respond in my REST API.
Valid example:
http://blah.com/api/v1/dosomething/123
The above request is valid and I currently have a HTTP status of 200 with a JSON response
{ "dosomething": { "status": "OK", "results": "123" } }
Now my question is: if the passed parameter is invalid (I expect a string of integers), do I return an HTTP 200 out of 200 response and pass the error status to a JSON response or should something pass as an HTTP 400 response (invalid request) and a list of errors / problems with request in JSON response?
Error example:
http://blah.com/api/v1/dosomething/123a
JSON answer:
{ "dosomething": { "status": "ERROR", "errors": [ "Value passed: |123a| must be a integer." ] } }
Again my question is, should I pass 200 or 400 HTTP status in the request, where the passed parameter is not what I expect? Or will it always be 200 response when the request is working?
What is considered best practice?
source share