json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Routing not working as expected

Open RicardoMonteiroSimoes opened this issue 4 years ago • 2 comments

Hello,

I'm trying to setup routing using routes.json, which doesn't appear to be working correctly.

Expected behaviour:

Calling /projects/1?_embed=offers returns the following JSON:

{
  "id": 1,
  "name": "Villa am See",
  "description": "Neubau in Zürich",
  "customer_id": "5ea53603bec1d053dfa4041d",
  "address": "Teststreet 123",
  "zip": "8001",
  "city": "Zurich",
  "created_at": "2020-04-07T15:44:02.921Z",
  "updated_at": "2020-04-07T15:44:02.921Z",
  "payment_target": "30 Tage",
  "offers": []
}

Observed behaviour:

/projects/1 with routing "projects/:id": "/projects/:id?_embed=offers" return this JSON:

{
  "id": 1,
  "name": "Villa am See",
  "description": "Neubau in Zürich",
  "customer_id": "5ea53603bec1d053dfa4041d",
  "address": "Teststreet 123",
  "zip": "8001",
  "city": "Zurich",
  "created_at": "2020-04-07T15:44:02.921Z",
  "updated_at": "2020-04-07T15:44:02.921Z",
  "payment_target": "30 Tage",
  "offers": [
    {
      "id": 2,
      "project_id": 1,
      "name": "Offer 1",
      "created_at": "2020-04-07T17:57:37.468Z",
      "updated_at": "2020-04-07T17:57:37.468Z",
      "discount": null,
      "employee_id": null,
      "entries": []
    },
    {
      "id": 3,
      "project_id": 1,
      "name": "Offer 2",
      "created_at": "2020-04-07T17:58:24.185Z",
      "updated_at": "2020-04-07T17:58:24.185Z",
      "discount": null,
      "employee_id": null,
      "entries": []
    }
  ]
}

Then there is the next problem, that using /projects/1/offers returns an empty array, instead of the offers only, as expected when reading the README: image

RicardoMonteiroSimoes avatar Apr 26 '20 09:04 RicardoMonteiroSimoes