I wanted to know how I should respond in my REST API.
Valid Example:
http://blah.com/api/v1/dosomething/123
The above is a valid request and currently I have a HTTP Status of 200 with a JSON response
{
"dosomething": {
"status": "OK",
"results": "123"
}
}
Now my question is, if the parameter passed is not valid ( I'm expecting a string of whole numbers ), do I return a HTTP Response of 200 and pass the error status back in the JSON response or should I pass something like a HTTP 400 response ( Bad request ) and list the error / issue with the request in the JSON response?
Error Example:
http://blah.com/api/v1/dosomething/123a
JSON Response:
{
"dosomething": {
"status": "ERROR",
"errors": [
"Value passed: |123a| must be a integer."
]
}
}
Again my question is should I pass a 200 or 400 HTTP status on the request where the parameter passed is not what I'm expecting? Or should this always be a 200 response as the request is working?
What is considered best practice?