繁体   English   中英

Rest API中的过滤参数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM