7

I have installed a Json-Server. Get-Requests to this server are delivering the expected data but now I want to add some search queries to my request. But the result is still the same. I don't know whats my mistake here.

Here is my request: http://localhost:3000/people?age=22

I also tried it with: http://localhost:3000/people?customer.age=22 but the result is still all data.

Thats my JSON-File:

 {
  "customer": [
    {
      "id": 1,
      "name": "Stefan Winkler",
      "phone_number": "017692601589",
      "age": "22",
      "education": "High School"
    },
    {
      "id": 2,
      "name": "Christoph Huber",
      "phone_number": "094462649",
      "age": "42",
      "education": "nothing"
    },
    {
      "id": 3,
      "name": "Michael Unholer",
      "phone_number": "093862649",
      "age": "12",
      "education": "Realschule"
    }
  ]
}
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Stefan Winkler
  • 71
  • 1
  • 1
  • 2
  • it's a node.js server i installed json-server(https://github.com/typicode/json-server) via npm – Stefan Winkler Jun 17 '19 at 15:00
  • 1
    Seems to work as expected on their example: https://jsonplaceholder.typicode.com/users?address.street=Victor%20Plains But your source data is an object and it should be an array – Jamiec Jun 17 '19 at 15:03
  • Did you try http://localhost:3000/customer?age=22 ? Is that you full DB, or the result that you get with a different query ? – SScotti Jun 17 '19 at 15:09

1 Answers1

17

try

http://localhost:3000/customer?age=22

[
  {
    "id": 1,
    "name": "Stefan Winkler",
    "phone_number": "017692601589",
    "age": "22",
    "education": "High School"
  }
]

http://localhost:3000/customer?name_like=rist

[
  {
    "id": 2,
    "name": "Christoph Huber",
    "phone_number": "094462649",
    "age": "42",
    "education": "nothing"
  }
]
  • How can you filter by two arguments, for instance name_like or age_like – MeatBALL Jul 19 '22 at 12:11
  • 1
    @MeatBALL You can use "&" to append to query params. For example, http://localhost:3000/customer?name_like=rist&education_like=high – Code With Me Aug 21 '22 at 11:06
  • How can I filter by a union of two arguments, for instance all items where title or description contains 'climate'? title_like=climate|description_like=climate is not working. – Szalai Laci Mar 12 '23 at 02:28