typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
72.95k stars 7.02k forks source link

or logic in filtering #938

Open stushurik opened 5 years ago

stushurik commented 5 years ago

In my db I have something like this:

[
  {
    "id": "89be578a-ef59-4cf2-96ca-5911bf95d959",
    "count": 1
  },
  {
    "id": "464e2921-2a44-4bfb-b533-89f2a75f8ba5",
    "count": 5
  },
  {
    "id": "111837ad-7b91-4fd3-b7c8-daa7b194e8fa",
    "count": 6
  },
  {
    "id": "111837ad-7b91-4fd3-b7c8-daa7b194e8fa",
    "count": 8
  },
  {
    "id": "111837ad-7b91-4fd3-b7c8-daa7b194e8fa",
    "count": 10
  }
]

And I would like to request like this

/connections?count=1&count_gte=8 

and get items with count 1,8 and 10.

Currently it seems that json-server applies some kind of "and" logic and this request become mutually exclusive. As a result I get empty array

Proposal allow "or" request

stushurik commented 5 years ago

@typicode what do you think about it?

MickL commented 3 years ago

I would love to see such an option! Maybe someone may fork this project #1219 ?

MickL commented 3 years ago

How would you define an "or" in the parameter?

Maybe with _or_: /connections?count=1_or_count_gte=8?

stushurik commented 3 years ago

I can imagine something like this: /connections?count=1&count_or_gte=8 Inspired by: https://gt-tech.bitbucket.io/spring-data-querydsl-value-operators/README.html https://gt-tech.bitbucket.io/spring-data-querydsl-value-operators/EXAMPLE_APPLICATION.html

MickL commented 3 years ago

I like. What about multiple fields? How is that done in spring? E.g.:

?idA=123_or_idB=123

oceangravity commented 3 years ago

Would be magic if can consider the Lucene or ElasticSearch syntax, it's really useful

MickL commented 3 years ago

How does the syntax look exactly?

oceangravity commented 3 years ago

Obviously it's add more complexity: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html