官术网_书友最值得收藏!

Filtering

Sometimes, a resource contains more data than is needed by the requester. In this case, the API should have the ability to filter elements in or out from the resource.

Filter in or out doesn't mean that the resource will change. Remember that GET methods are idempotent. It will only remove from the response, but the original information will still be available.

Filtering can be implemented as a query parameter that's named for the field to be filtered on. The value needs to be the value it needs to filter for. You can refer to the definition of filtering at https://jsonapi.org/recommendations/#filtering.

For example, the following is a request for all items associated with a particular order with a name of coffee:

GET http://<HOST>/order/<id>/items?filter[name]=coffee

Also, multiple filter values could be combined in a comma-separated list:

GET http://<HOST>/order/<id>/items?filter[name]=coffee,milk

Furthermore, multiple filters can also be applied to the same request as another filter:

GET http://<HOST>/order/<id>/items?filter[name]=coffee,milk&filter[category]=organic

There is also the possibility to include the following operators:

  • in: Getting items within the range between 5 and 20:
GET http://<HOST>/order/<id>/items?filter[size]=in:5,20
  • nin: Getting items that are out of a range:
GET http://<HOST>/order/<id>/items?filter[size]=nin:5,20
  • neq: Getting items not matching a specific value:
GET http://<HOST>/order/<id>/items?filter[category]=neq:built-in
  • gt: Getting items greater than a specific value:
GET http://<HOST>/order/<id>/items?filter[size]=gt:5
  • gte: Getting items greater than a specific value, inclusive:
GET http://<HOST>/order/<id>/items?filter[size]=gte:5
  • lt: Getting items lower than a specific value:
GET http://<HOST>/order/<id>/items?filter[size]=lt:25
  • lte: Getting items lower than a specific value, inclusive:
GET http://<HOST>/order/<id>/items?filter[size]=lte:25

主站蜘蛛池模板: 利川市| 山东省| 都安| 潞城市| 申扎县| 姚安县| 怀集县| 新晃| 象州县| 孙吴县| 东乡族自治县| 桐乡市| 灵武市| 东至县| 紫阳县| 宿州市| 湟中县| 伽师县| 鹿邑县| 桑日县| 萝北县| 嘉禾县| 龙南县| 迁安市| 阜城县| 江西省| 宾阳县| 且末县| 囊谦县| 额济纳旗| 十堰市| 新安县| 江西省| 阜新市| 沈阳市| 双辽市| 邹城市| 郸城县| 石屏县| 名山县| 溆浦县|