JSON:API 中不区分大小写的过滤

Case insensitive filtering in JSON:API

我正在尝试对 json:api 端点执行筛选。 如果 db 中的名称恰好是 test name?filter[name]=test name 工作正常。但是如果名称是 Test nametEst name 或任何其他可能的组合,我希望服务器 return 我的值。我该怎么做?

谢谢。

JSON:API规范没有定义过滤策略:

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

它包含与您的 URL 设计相匹配的过滤策略建议:

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

但即使是该建议也没有涵盖应该使用什么比较运算符。它也不包括是否应该区分大小写。这取决于具体实现选择的过滤策略。

请注意,在 URL 中编码比较运算符的策略也是有效的。例如。您可以像这样在查询参数中编码比较运算符:

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

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

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