Hi everyone!
I'm having some trouble with access to nested resources.
I'd like to query api/users/:user_id/searches in order to query all the searches of a user. When I do GET searches?user_id=123 everything is fine, but when I do GET api/users/123/searches json-server's response is not filtered by user_id and also search with different user_id are shown. What am I missing?
Thank you in advance,
Manuel
_routes.json_
{
"/api/": "/",
"/api/users/:user_id/searches": "/searches?user_id=:user_id"
}
_db.json_
{
"searches": [
{
"id": 1,
"user_id": 123,
"type": "by-destination",
"params": {}
},
{
"id": 2,
"user_id": 123,
"type": "by-destination",
"params": {}
},
{
"id": 3,
"user_id": 121,
"type": "by-destination",
"params": {}
}
]
}
The same thing happened to me when I updated to the latest version of json-server. You now need to have the following as the route for /api:
{
"/api/*": "/$1"
}
The README.md file shows examples of the new routing format, but I couldn't find any mention of the breaking change. It would be great if such a note was added to the README.md file.
Hi @RobertBernstein,
Thanks for the help.
You can find them in the CHANGELOG file and I bump the minor version when there's a breaking change :)
https://github.com/typicode/json-server/blob/master/CHANGELOG.md#0110---2017-07-05
Thank you, @typicode! I just missed seeing that. I'll keep that in mind for the future.
Most helpful comment
The same thing happened to me when I updated to the latest version of json-server. You now need to have the following as the route for /api:
The README.md file shows examples of the new routing format, but I couldn't find any mention of the breaking change. It would be great if such a note was added to the README.md file.