gpt4 book ai didi

python - 在 Eve 中,如何创建集合的子资源并保留父集合端点?

转载 作者:太空狗 更新时间:2023-10-30 01:22:07 27 4
gpt4 key购买 nike

我想要这三个端点:

/games
/images
/games/<game_id>/images

这是我的 settings.py 文件的摘录

#...

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"
}
#...

如果省略 url 属性,则在 GET/时会得到两个预期的端点:

/games

/images

但是如果您包含 url 属性,则无法点击/images 而只能点击/games 和 /games/<game_id>/images如下所示:

{
"_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"
}
]
}
}

我怎样才能保留集合图像并仍然通过子资源查询使其文档可用?

最佳答案

您可以设置 3 个不同的端点,而其中两个端点使用相同的数据库资源(图像)。像这样:

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"}
}

有关引用,请参阅 Multiple API Endpoints, One Datasource .

关于python - 在 Eve 中,如何创建集合的子资源并保留父集合端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26166344/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com