Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status code for malformed POST body

Tags:

What status code should a REST service return in response to a POST request containing a malformed / unparseable message body?

like image 330
Frederick The Fool Avatar asked Dec 12 '11 13:12

Frederick The Fool


People also ask

What is HTTP status code1?

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.

What are status code 2xx 3xx 4xx 5xx in API?

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.

When should I use HTTP 400?

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).

What is the HTTP response code for a POST request with incorrect parameters?

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).


2 Answers

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.

like image 113
Rob Hruska Avatar answered Sep 21 '22 00:09

Rob Hruska


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.

like image 38
Andy Avatar answered Sep 24 '22 00:09

Andy