Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

400 BAD request HTTP error code meaning?

I have a JSON request which I'm posting to a HTTP URL.

Should this be treated as 400 where requestedResource field exists but "Roman" is an invalid value for this field?

[{requestedResource:"Roman"}]  

Should this be treated as 400 where "blah" field doesn't exist at all?

[{blah:"Roman"}] 
like image 529
Phoenix Avatar asked Oct 29 '13 23:10

Phoenix


People also ask

What causes HTTP 400 Bad Request?

The HTTP error 400 can occur due to incorrectly typed URL, malformed syntax, or a URL that contains illegal characters. This is surprisingly easy to do by mistake and can happen if a URL has been encoding incorrectly.

What does 400 there was a problem with your request mean?

What does 400 mean on Roblox? When you are receiving a 400 bad request error on Roblox on your gaming device, it simply means you are trying to access a page that is either down for maintenance or you have a firewall problem.


2 Answers

A 400 means that the request was malformed. In other words, the data stream sent by the client to the server didn't follow the rules.

In the case of a REST API with a JSON payload, 400's are typically, and correctly I would say, used to indicate that the JSON is invalid in some way according to the API specification for the service.

By that logic, both the scenarios you provided should be 400s.

Imagine instead this were XML rather than JSON. In both cases, the XML would never pass schema validation--either because of an undefined element or an improper element value. That would be a bad request. Same deal here.

like image 85
Vidya Avatar answered Sep 21 '22 11:09

Vidya


From w3.org

10.4.1 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 30
Jason Sperske Avatar answered Sep 20 '22 11:09

Jason Sperske