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

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

You can send a 400 Bad Request code. It’s one of the more general-purpose 4xx status codes, so you can use it to mean what you intend: the client is sending a request that’s missing information/parameters that your application requires in order to process it correctly.

Why is my 400 Bad 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 (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

When to use a 400 Bad Request status code?

A “400 Bad Request” status code indicates that the http request could not be understood – this is pretty much only related to wel-formedness of the request header and rarely (if ever) used when the post data is malformed, and should be used only when the server is unable to interprete the request. This is not the case here.

What’s the difference between HTTP status code 400 and 422?

HTTP status code 422 states: The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415 (Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process

Why is my HTTP status code not working?

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications. This description doesn’t quite fit the circumstance; but, if you go by the list of core HTTP status codes defined in the HTTP/1.1 protocol, it’s probably your best bet.

When to return a 404 or a 400?

400 would be when the resource is found, but the request itself is malformed. ii. https://api.domain.com/v1/resource/foobar where foobar DOES exist, but the request is wrong ( {age:”NOTANINTEGER”}, a string instead of an int for example), it should return 400. Hope I could help. 404 would be a more common practice one. Its for Resource Not Found.