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?
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
...
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"
}
]
}
like this it is works:
/building/H/room
but following doesn't work:
/building/H/room/112/funktion
it is possible to get a solution for this relation?
Br
Jakob
@typicode Will you work on nested support in the future?
Most helpful comment
Hello,
I would like to ask, if is it possible get two relations, for example:
like this it is works:
/building/H/room
but following doesn't work:
/building/H/room/112/funktion
it is possible to get a solution for this relation?
Br
Jakob