Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多对多资源映射restful api设计_Rest_Express_Api Design_Restful Url - Fatal编程技术网

多对多资源映射restful api设计

多对多资源映射restful api设计,rest,express,api-design,restful-url,Rest,Express,Api Design,Restful Url,这里还有许多其他问题,它们针对的是restful API的多对多关系url设计。我有一些相同的方法,但它不同于其他方法。我找不到更好的方法 我有位置资源和服务资源` 我遇到的问题是,我必须设计一条路线,提供所有地点及其提供的服务 我浏览了一篇关于这一点的帖子。 GET/locations?include=服务 我也经历了另一次。这是我的建议。 GET/locations服务 我相信我不是第一个有这种困惑的人。请帮忙,如果可能的话,分享一些资源,我可以通过这些资源来消除我的疑虑 您可以使用

这里还有许多其他问题,它们针对的是restful API的多对多关系url设计。我有一些相同的方法,但它不同于其他方法。
我找不到更好的方法

我有
位置
资源和
服务
资源`


我遇到的问题是,我必须设计一条路线,提供所有地点及其提供的服务

我浏览了一篇关于这一点的帖子。
GET/locations?include=服务


我也经历了另一次。这是我的建议。
GET/locations服务



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

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

但是

是一个完全令人满意的URI

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

这些都很好。通用组件不在乎,只要您使用符合

定义的生产规则的拼写,我认为REST不会考虑立即加载。这在图形服务中更为典型。我会选择
GET/locations?include=services
,因为它可以扩展。也许在未来,您将需要更迫切的资源:
GET/locations?include=services&population
用restful的方式做同样的事情会是什么。还有别的办法吗?问题是我不喜欢这种方法。我必须根据传递的include进行许多if和代码重复,以便快速加载。expressjs是否对
/locations
/locations?include=service
/locations?include=services&population
进行不同的处理?否。它将执行相同的路由。您只需访问查询字符串并在单个位置进行检查。我会选择
/locations?include=services
更有意义,并且正如@Rashomon所建议的,如果需要,我可以执行更多include操作。
/a1dadfcb-8fc6-4456-b05e-a0b91575e0ef
/locations?include=services
/locations?services
/locations-services
/locations/services
/service-directory