多对多资源映射restfulapi设计

Many to many resource mapping restful api design

这里还有许多针对同一问题的其他问题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 上浏览了一个 post 的建议。
GET /locations?include=services

我还经历了另一个 doc 。它建议。
GET /locations-services

我相信我不是第一个有这种困惑的人。
请帮忙,如果可能的话分享一些资源,我可以通过这些资源来消除我的疑虑。

您可以使用任何您想要的拼写。您应该选择与您用于其他标识符的拼写一致的拼写,原因与我们选择与其他局部变量名的拼写一致的变量名的拼写相同。

但是

/a1dadfcb-8fc6-4456-b05e-a0b91575e0ef

是一个非常令人满意的 URI。

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

这些都很好。通用组件无所谓,只要你使用符合RFC 3986

定义的生产规则的拼写即可