typicode / json-server

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

Multiple filters not working #1531

Open AsilbekMelikov opened 6 months ago

AsilbekMelikov commented 6 months ago
GET /electronics?id=1&id=2

When I tried to use filter based on this filter json-server did not response correctly.

[
  {
    "id": "1",
    "model": "samsung",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 22.png",
    "camera": "black"
  },
  {
    "id": "2",
    "model": "apple",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "plastic cover",
    "category": "smartphone",
    "image": "/Assets/images/image 23.png",
    "camera": "black"
  },
  {
    "id": "3",
    "model": "huawei",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "8GB Ram",
    "category": "smartphone",
    "image": "/Assets/images/image 28.png",
    "camera": "white"
  },
  {
    "id": "4",
    "model": "pocco",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "super power",
    "category": "smartphone",
    "image": "/Assets/images/image 32.png",
    "camera": "black"
  },
  {
    "id": "5",
    "model": "lenovo",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "large memory",
    "category": "smartphone",
    "image": "/Assets/images/image 33.png",
    "camera": "white"
  },
  {
    "id": "6",
    "model": "samsung",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 34.png",
    "camera": "black"
  },
  {
    "id": "7",
    "model": "apple",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 35.png",
    "camera": "red"
  },
  {
    "id": "8",
    "model": "huawei",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 23.png",
    "camera": "green"
  },
  {
    "id": "9",
    "model": "lenovo",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 22.png",
    "camera": "black"
  },
  {
    "id": "10",
    "model": "samsung",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 35.png",
    "camera": "black"
  },
  {
    "id": "11",
    "model": "apple",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "plastic cover",
    "category": "smartphone",
    "image": "/Assets/images/image 33.png",
    "camera": "black"
  },
  {
    "id": "12",
    "model": "huawei",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "8GB Ram",
    "category": "smartphone",
    "image": "/Assets/images/image 34.png",
    "camera": "white"
  },
  {
    "id": "13",
    "model": "pocco",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "super power",
    "category": "smartphone",
    "image": "/Assets/images/image 32.png",
    "camera": "black"
  },
  {
    "id": "14",
    "model": "lenovo",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "large memory",
    "category": "smartphone",
    "image": "/Assets/images/image 22.png",
    "camera": "white"
  },
  {
    "id": "15",
    "model": "samsung",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 23.png",
    "camera": "black"
  },
  {
    "id": "16",
    "model": "apple",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 28.png",
    "camera": "red"
  },
  {
    "id": "17",
    "model": "huawei",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 34.png",
    "camera": "green"
  },
  {
    "id": "18",
    "model": "lenovo",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 33.png",
    "camera": "black"
  },
  {
    "id": "10",
    "model": "samsung",
    "realPrice": "1128",
    "bonusPrice": "99.50",
    "feature": "metallic",
    "category": "smartphone",
    "image": "/Assets/images/image 35.png",
    "camera": "black"
  }
]

This is my db.json array was got by http://localhost:3000/electronics this one. But I want to get two same properties in a single filter string. like ?id=10&id=8 so on. How can I do it?

kacou12 commented 2 months ago

I had the same problem, I happened to be using the alpha version of json server, if you install the current stable version (0.17.4), which can be found here: (https://github.com/typicode/json-server/tree/v0) , you'll see that everything works fine.