Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested request without any ids #514

Open
melnikovic opened this issue Apr 11, 2017 · 3 comments
Open

Nested request without any ids #514

melnikovic opened this issue Apr 11, 2017 · 3 comments

Comments

@melnikovic
Copy link

Hey guys,
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": {}
    		}
    	}
    }

Json as above is throwing 404. So any idea what I am doing wrong?

@typicode
Copy link
Owner

typicode commented Apr 12, 2017

Hey @melnikovic

Nested requests to access nested resources aren't supported. At least, not with this data structure.

I would suggest flattening db.json and prefix your requests with a custom route.

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

https://github.com/typicode/json-server#add-custom-routes

{
  "/rest/user/": "/"
}

Then you'll be able to access each resources

GET /rest/user/select
GET /rest/user/orgs
GET /rest/user/orgs/:id
...

@ichbinder
Copy link

Hello,
I would like to ask, if is it possible get two relations, for example:

{
  "building": [
    {
      "id": "H",
      "name": "Home"
    }
  ],
  "room": [
    {
      "id": "112",
      "buildingId": "H",
      "name": "112"
    }
  ],
  "funktion": [
    {
      "id": 1,
      "roomId": "112",
      "ga": "2/1/20",
      "DPT": "DPT1",
      "commit": "Hello"
    }
  ]
}
  1. like this it is works:
    /building/H/room

  2. but following doesn't work:
    /building/H/room/112/funktion

it is possible to get a solution for this relation?

Br
Jakob

@oyaaraas
Copy link

@typicode Will you work on nested support in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants