Imagine I have an endpoint on a REST API that only supports these sort parameters: date and price. How should I react to an API call that asks data sorted by tax-rate?
For a filter param it's a no brainer, I return empty list. but should I do the same for a sort param or simply ignore the invalid sort param and return the data based other other parameters?
I know in some cases there's no strict answer to API-design questions, I'm curious to know which approach supports a wider range of use-cases.
I guess in both cases either unknown filter or unknown sort type, API should respond with same response. Such response generally reside in Client Errors (400-499)
categories.
And reason is APIs should have strict and defined specification. And such specifications explicitly mention valid filter types and valid sort types. If any request which don't satisfy with specification should be result into 400* error ranges. That's what I think preferable response would be, so client making request also knows that he violates the API specification.
In my experience, I have seen many specifications as well which mention to ignore unknown parameters from the request. And in that case result in a default response. If your API document that in your specification clearly then it's a valid response.