REST API filter operator best practice

后端 未结 4 1712
无人共我
无人共我 2021-02-05 03:21

I am building a REST API that uses a filter parameter to control search results. E.g., one could search for a user by calling:

GET /users/?filter=na         


        
4条回答
  •  太阳男子
    2021-02-05 03:45

    There seems to be a lot of standards (like OData), but many are quite complicated in that they introduce new syntax.

    For simple multi filtering the following format avoid polluting the parameter namespace while still standing on top of existing web-technology

    GET /users?filter[name]=John&filter[title]=Manager
    

    It's easily readable and on the backend languages like PHP will receive it as an array of filters to apply.

提交回复
热议问题