What status code should a REST service return in response to a POST request containing a malformed / unparseable message body?
Prevailing theory is that the status is set to null and the statuscode set to -1 when the response object is constructed, and then something happens to the connection that means the request doesn't complete, so these defaults are never overwritten with real values.
2xx successful – the request was successfully received, understood, and accepted. 3xx redirection – further action needs to be taken in order to complete the request. 4xx client error – the request contains bad syntax or cannot be fulfilled. 5xx server error – the server failed to fulfil an apparently valid request.
The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing).
HTTP status codes the server can generate in response to HTTP requests: 200 OK : Successful request. 400 Bad Request : Invalid argument (invalid request payload). 403 Forbidden : Permission denied (e.g. invalid API key).
400 Bad Request
Straight from the specification:
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
Alternatively, if you need a more specific status you can create your own 4XX status for whatever API you might be designing.
400 - Bad Request
From Hypertext Transfer Protocol -- HTTP/1.1 (RFC-2616):
400 Bad Request
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
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