POST/PUT on REST JSON API when property doesn't exist POST/PUT on REST JSON API when property doesn't exist json json

POST/PUT on REST JSON API when property doesn't exist


HTTP 422: Unprocessable Entity

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 the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions. RFC4918

A common practice is NOT to add valid message properties if the message also contains invalid properties.


A common rule for a server is to be generous in what you accept and strict in what you produce.

I'd prefer to accept such an input and get as much as possible out of it. Any unknown property of the input would be ignored.


When answering that question you have to consider versioning too. Do you support old clients that send fewer arguments than expected - that could work with suitable defaults. Or do you have more than one server implementation such that newer clients would be sending too many arguments for an older server implementation? If the answer is yes to one of these then you have to be careful about rejecting inputs.