简体   繁体   English

具有复合ID的REST API设计

[英]REST API Design with Composite ID

What is the best way to design a RESTful resource for an object with a composite id? 为具有复合ID的对象设计RESTful资源的最佳方法是什么? For example, suppose I have a GET /people resource for getting a list of person records. 例如,假设我有一个GET /people资源来获取人员记录列表。 A person doesn't have a single id; 一个人没有一个身份证; instead, it is identified by firstName, lastName, and birthdate. 相反,它由firstName,lastName和birthdate标识。 How should I design the resource to get a single person? 我该如何设计资源以获得一个人?

I would use one of the following variations: 我会使用以下变体之一:

GET /people/John/Smith/1973-12-01

or 要么

GET /people/John,Smith,1973-12-01

正如评论中已经提到的,如果您没有确保唯一性的单个标识符,您可以考虑矩阵变量

GET /people;firstname=John;lastname=Smith;birthday=1973-12-01

关于什么 :

GET /people/firstName/X/lastName/Y/birthdate/AAAA-MM-DD

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

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