简体   繁体   English

具有复合ID的REST资源的URL

[英]URL to REST resource with a composite ID

I'm creating a REST API where some of my resources have a composite ID made of two separate parts. 我正在创建一个REST API,其中我的一些资源具有由两部分组成的复合ID。 An example is a resource for a given latitude and longitude. 一个示例是给定纬度和经度的资源。

My initial thoughts were to add each composite part of the ID as a separate part of the path as per below: 我最初的想法是将ID的每个组合部分添加为路径的单独部分,如下所示:

http://localhost/phone-details/Vodafone/07123000000 - Operator and number

http://localhost/location-details/50/-2 - Lat and long

Is this best practice to take this approach? 这是采用这种方法的最佳实践吗? Should perhaps query strings be used so each composite ID part has a clear and obvious name? 也许应该使用查询字符串,以便每个复合ID部件都有一个清晰明显的名称? Alternatively should the composite IDs just be passed across separated by a comma? 或者,是否应仅以逗号分隔的方式传递复合ID?

I can suggest you good book Restful web services cookbook From there (p.77) 我可以为您推荐一本好书宁静的Web服务指南从那里开始(p.77)

Use the comma ( , ) and semi-colon ( ; ) characters to indicate nonhierarchical portions of the URI. 使用逗号(,)和分号(;)字符表示URI的非分层部分。

The semicolon convention is used to identify matrix parameters: 分号约定用于标识矩阵参数:

http://www.example.org/co-ordinates;w=39.001409,z=-84.578201 http://www.example.org/axis;x=0,y=9 http://www.example.org/co-ordinates;w=39.001409,z=-84.578201 http://www.example.org/axis;x=0,y=9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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