I have a request which i post in a json to a http url

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


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

Best Answer

A 400 means that the request was malformed. In other words the stream of data sent to the server by the client 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 that this was xml rather than json The xml would never pass schema validation because of either an undefined element or an improper element value That would be a bad request. Same deal here.