I have a RESTFul service with 2 query parameters, say paramOne
& Paramtwo
The possible URLs would be
http://someApi/someResource?paramone=1¶mtwo=2
http://someApi/someResource?paramone=1
http://someApi/someResource?paramtwo=2
The relation between paramOne
& Paramtwo
is one to many. So, with second route the result would contain a collection of objects. Now, if parameters we send are invalid, then the service would return 400 BAD REQUEST
.
Here comes my question. If a user requests by giving one valid and other invalid param like http://someApi/someResource?paramone=1¶mtwo=invalidData
then what woould be the HTTP status code? Is it a BAD REQUEST
? Or a collection of objects based on paramone
? (As paramone is valid)
From the Robustness Principle: "Be conservative in what you do [send], be liberal in what you accept.", I would expect a collection and neglect the invalid Paramtwo
. And, when it comes to DELETE
operation, this deletes all the objects with paramone
. So is it OK to have this or it should be badrequest?
Thanks :)
In REST an URI should be treated as an atomic identifier, including the querystring. In theory, that means you should return 404 Not Found
, even though the base resource to which the querystring is applied exists. However, I believe most APIs are more pragmatic about that and tend to return 400 Bad Request
on invalid querystring parameters, based on the principle of least astonishment. If that's adopted consistently, fine.
I believe it's better to reject the whole request with a clear indication of the error and expect the user to correct it, than giving a partial success where the user might overlook the error. If you want the request to succeed partially, HTTP has no standard for that, but you may adopt the 207 Multi-Status
WebDav response if you want.