Case insensitive filtering in JSON:API

787 views Asked by At

I am trying to perform a filter on a json:api endpoint. ?filter[name]=test name works fine if the name in db is exactly test name. But I want the server to return me values if name is Test name,tEst name or any other combination possible. How can I do this?

Thank you.

1

There are 1 answers

0
jelhan On BEST ANSWER

The JSON:API specification does not define the filter strategy:

JSON:API is agnostic about the strategies supported by a server. The filter query parameter can be used as the basis for any number of filtering strategies.

https://jsonapi.org/format/#fetching-filtering

It contains a recommendation for filtering strategy that matches your URL design:

It’s recommended that servers that wish to support filtering of a resource collection based upon associations do so by allowing query parameters that combine filter with the association name.

For example, the following is a request for all comments associated with a particular post:

GET /comments?filter[post]=1 HTTP/1.1

https://jsonapi.org/recommendations/#filtering

But even that recommendation does not cover what comparison operator should be used. It also doesn't cover if that should be case sensitive or not. It depends on the filtering strategy picked by the concrete implementation.

Please note that also a strategy encoding the comparison operator in the URL would be valid. E.g. you may encode the comparison operator in the query parameter like this:

GET /companies?filter[name][equalsCaseInsensitive]=test%20name

GET /companies?filter[name][equalsCaseSensitive]=test%20name

GET /companies?filter[sales][greaterThan]=100000