12

I just start using json-server and struggling with one thing. I want to have URL which are nested so e.g. to get user orgs, request would looks like: /rest/user/orgs and will return array of user orgs

{
    "rest": {
        "user": {
            "select": {
                "org": []
            },
            "orgs": [{
                "id": "5601e1c0-317c-4af8-9731-a1863f677e85",
                "name": "DummyOrg"
            }],
            "logout": {}
        }
    }
}

Any idea what I am doing wrong?

Andurit
  • 5,612
  • 14
  • 69
  • 121

1 Answers1

2

This is not supported by the library. The way to get this working is to add a custom routes file to de server, where you will map (or redirect) requests made to /rest/user/ to /.

db.json

 {
            "select": {
                "org": []
            },
            "orgs": [{
                "id": "5601e1c0-317c-4af8-9731-a1863f677e85",
                "name": "DummyOrg"
            }],
            "logout": {}
    }

routes.json

{
  "/rest/user/*": "/$1"
}

and then run it using json-server db.json --routes routes.json

Nicolas
  • 1,193
  • 1
  • 10
  • 25