[英]Filtering parameters in Rest API
我有兩個實體“個人”和“業務”,並且它們都有一個子資源(例如位置)
所以我有端點:
GET /persons/{id}/locations
GET /businesses/{id}/locations
現在,我希望端點過濾主資源的位置。 如果我做:
GET /persons/{id}/locations?country={...}
GET /businesses/{id}/locations?country={...}
我將搜索特定人員/公司的位置。
什么是過濾所有人的最佳實踐,我有一些想法:
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": [...]}
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.