许多资源映射宁静的api设计

问题描述 投票:0回答:1

这里还有许多其他针对同一问题的问题many-to-many relationship url design for restful apis。我有些相同,但与其他有所不同。我找不到更好的方法。我有locations资源和services资源`

GET /services                           //it should give you all services
GET /locations                          //it should give you all locations
GET /locations/:id/services             //it should give you all services offered by a location

我的问题是我必须设计一条路线,该路线可以提供所有位置以及他们提供的服务我在reddit上发表了一篇建议。GET /locations?include=services我还经历了另一个doc。它建议。GET /locations-services我确信我不是第一个有这种困惑的人。请提供帮助,并在可能的情况下分享一些我可以用来消除疑虑的资源。

rest express api-design restful-url
1个回答
0
投票

您可以使用所需的任何拼写。出于与我们选择与其他本地变量名称一致的变量名称拼写相同的原因,您应该选择与用于其他标识符的拼写一致的拼写。

但是

/a1dadfcb-8fc6-4456-b05e-a0b91575e0ef

是完全令人满意的URI。

/locations?include=services
/locations?services
/locations-services
/locations/services
/service-directory

这些都是fine。通用组件无关紧要,只要您使用与RFC 3986

定义的生产规则一致的拼写
© www.soinside.com 2019 - 2024. All rights reserved.