In Eve, how can you make a collection sub-resource and keep the endpoint of the parent collections?
I need these three endpoints:
/games
/images
/games/<game_id>/images
Here's an excerpt from my settings.py file
#...
games = {
"schema": {
"title": {
"type": "string",
"required": True
},
"name": {
"type": "string",
"required": True
},
}
}
images = {
"schema": {
"game_id": {
"type": "string",
"required": True,
},
"title": {
"type": "string",
"required": True,
},
},
"url": "games/<regex('[a-f0-9]{24}'):game_id>/images"
}
#...
If you leave out the url property, you get two expected endpoints when you GET /:
/games /images
But if you include url property you cannot hit / images and instead you can only use hit / games and /games/<game_id>/images
like below:
{
"_links": {
"child": [
{
"href": "/games/<regex('[a-f0-9]{24}'):game_id>/images",
"title": "games/<regex('[a-f0-9]{24}'):game_id>/images"
},
{
"href": "/games",
"title": "games"
}
]
}
}
How can I store the images of a collection and still make my documents available through a resource request?
+3
source to share
1 answer
You can configure 3 different endpoints, whereas two of them are consuming the same database resource (images). Something like that:
images_schema: {
"game_id": {
"type": "string",
"required": True,
},
"title": {
"type": "string",
"required": True,
},
}
games = {
"schema": {
"title": {
"type": "string",
"required": True
},
"name": {
"type": "string",
"required": True
},
}
}
images = {
"schema": images_schema,
"url": "images" # not really needed
}
games_images = {
"schema": images_schema,
"url": "games/<regex('[a-f0-9]{24}'):game_id>/images",
"datasource": {"source": "images"}
}
For reference, see Multiple API Endpoints, One Data Source .
+2
source to share