How to desing RESTful advanced search/filter

前端 未结 1 713
慢半拍i
慢半拍i 2020-12-30 16:35

First of all, I have read RESTful URL design for search and How to design RESTful search/filtering? questions. I am trying to design more advanced options for searching in a

相关标签:
1条回答
  • 2020-12-30 17:09

    There are several options here. But it's clear that if your queries tend to be complex with operators, and so on... you can't use a set of query parameters. I see two approaches:

    • Provide the query as JSON content to a method POST
    • Provide the query in a query parameter with a specific format / grammar to a method GET

    I think that you could have a look at what ElasticSearch for their queries. They are able to describe very complex queries with JSON contents (using several levels). Here is a link to their query DSL: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html.

    You can also have a look at what OData does for queries. They choose another approach with a single query parameter $filter. Here are some links that can give you some examples: https://msdn.microsoft.com/en-us/library/hh169248(v=nav.70) and http://www.odata.org/documentation/odata-version-3-0/url-conventions/. This option requires to have a grammar on the server side to parse your query.

    In general, this link could also give you some hints at this level in its section "Filtering data": https://templth.wordpress.com/2014/12/15/designing-a-web-api/.

    Hope it gives you some helpful hints to design your queries within your RESTful services ;-)

    Thierry

    0 讨论(0)
提交回复
热议问题