【发布时间】:2020-05-30 00:43:02
【问题描述】:
这里还有许多其他问题针对同一问题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 不考虑预加载。这在图服务中更为典型。我会选择
GET /locations?include=services,因为它可以扩展。也许将来你会需要更多热切的资源:@987654330@ -
什么是做同样的宁静的方式。还有其他方法吗?问题是我这种方法。我必须做很多 if 和代码重复,以便根据传递的包含进行预加载。
-
expressjs 对
/locations、/locations?include=service和/locations?include=services&population的处理方式不同吗? -
没有。它将执行相同的路线。您只需访问查询字符串并在一个地方检查它们。
标签: rest express api-design restful-url