Say I have an API resource named "Foo" with property "bar" and I make the POST operation available to create a new instance:
POST /api/foo
{
"bar": "whatever"
}
If the user of my API mis-types the property like so:
POST /api/foo
{
"bat": "whatever"
}
There is no error.
I could add a NotNull constraint on the property "bar" so that if "bar" was not included, then an error would be thrown, but what to do if "bar" is nullable? Right now the result will be that "bar" becomes NULL and that is not what the end user expected.
Alternately, if any additional properties are added, there is no error or warning thrown, for example if "publish" is not a property but the following is submitted:
POST /api/foo
{
"bar": "whatever",
"publish": true
}
There is no error or warning about the unexpected "publish" property. The end user might expect this property to be available, possibly because it exists on other resources, but there is no error in the response. Obviously the end user should be reading documentation, but I would prefer giving feedback directly in the response to ensure 100% compliance.
In summary: If users of my API add erroneous properties, or accidentally mistype property names, how can I detect this and throw an error?