简体   繁体   中英

Pass filer search for restful api

If I want to pass an array of filters to a restful API like:

  - filter[color]=red&filter[size]=large&filter[brand]=brand_1,brand_2

Is there any best practice to do this? and what if I don't know -as an API framework- the names of filters (color,brand....) because these filters are related to the search?

And the final point if i want to pass this filter with operator for example color not in [red,blue] or price greater than 100$?

To my mind, the best practice here is to use the QueryString to pass your filters. In this case, you don't need this "filter[key]" stuff. You have to pass only the fields you want to use as filters, like color=red&size=large&brand=brand1,brand2 .

Regarding filters using operators... you can pass one more field called "query" or just "q" and pass your "search query" inside it. Lots of APIs use this approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM