In a REST API interface, should I explicitly check that the client used only the parameters used by the API, and return a HTTP 403 if a parameter the API doesn't know about was included in the request?
A bit of context. I'm working on a API which minifies JavaScript and LESS files. Originally, JavaScript files were minified using Google Closure Compiler. Since Closure Compiler has multiple optimization levels (whitespace only, simple optimizations and advanced optimizations), the API also made it possible for the caller to specify (optionally) the level, so:
POST http://example.com/api/v1/js?level=whitespace
and:
POST http://example.com/api/v1/js?level=advanced
would in most cases give different results.
Recently, I had to add support for ES6. Given the lack of proper support for ES6 by Closure Compiler, I added YUI Compressor. Since this one doesn't have optimization levels, the call is now simply:
POST http://example.com/api/v1/es6
Following POLA, I have an impression that I can't let the callers use the API like this:
POST http://example.com/api/v1/es6?level=advanced
because they would expect a specific result, but get a different one. The solution would be to check for the presence of level
parameter in the URI and return a error message indicating that the parameter is not supported.
But I check for this specific parameter, why not checking for lecel
(a typo), or optimize
(a guess), or anything else?
Therefore, is the API expects parameters a
, b
and c
to be possibly included in the URI, what should be the response if the URI also contains d
or e
?