restapi中的参数过滤
我有两个实体“个人”和“企业”,它们都有一个子资源(例如地点) 所以我有端点:restapi中的参数过滤,rest,api,api-design,Rest,Api,Api Design,我有两个实体“个人”和“企业”,它们都有一个子资源(例如地点) 所以我有端点: GET /persons/{id}/locations GET /businesses/{id}/locations 现在我需要一个端点来过滤主资源的位置。 如果我这样做: 我将搜索特定人员/企业的位置 过滤所有人员位置的最佳实践是什么 我有一些想法: 1. GET /persons/locations?country={...} 2. GET /locations?entity=persons&co
GET /persons/{id}/locations
GET /businesses/{id}/locations
现在我需要一个端点来过滤主资源的位置。
如果我这样做:
我将搜索特定人员/企业的位置
过滤所有人员位置的最佳实践是什么
我有一些想法:
1. GET /persons/locations?country={...}
2. GET /locations?entity=persons&country={...}
但不确定这些是否正确。您可以使用扩展概念,在其中可以使用实体之间的关系
GET /persons
{
"data": [
{"person_id": 1},
{"person_id": 2}
],
"links": [
{
"rel": "locations",
"href": "/person/1/locations"
},
{
"rel": "locations",
"href": "/person/2/locations"
}
]
}
GET /persons?expand=locations&country={...}
{
"data": [
{"person_id": 1, "locations": [...]},
{"person_id": 2, "locations": [...]}
]
}
您可以使用扩展概念,其中可以使用实体之间的关系
GET /persons
{
"data": [
{"person_id": 1},
{"person_id": 2}
],
"links": [
{
"rel": "locations",
"href": "/person/1/locations"
},
{
"rel": "locations",
"href": "/person/2/locations"
}
]
}
GET /persons?expand=locations&country={...}
{
"data": [
{"person_id": 1, "locations": [...]},
{"person_id": 2, "locations": [...]}
]
}