What is the best way to design a RESTful resource for an object with a composite id? For example, suppose I have a GET /people
resource for getting a list of person records. A person doesn't have a single id; instead, it is identified by firstName, lastName, and birthdate. How should I design the resource to get a single person?
Asked
Active
Viewed 2,475 times
6

jwzirilli
- 223
- 1
- 8
-
2By the way, although its very rare, two person with the same name, can have the same bithday. So this is quite a poor choice for a PK. – meskobalazs Jul 07 '15 at 15:15
-
1This is a hypothetical example. Please operate under the assumption that firstName, lastName, and birthdate guarantee uniqueness. – jwzirilli Jul 07 '15 at 15:21
-
2I agree with @jwzirilli - you should use a mechanism that (almost) guarantees the uniqueness of a person. The social security number f.e. would be such a number for persons. If in your system a combination of `firstName`, `lastName` and `birthday` is guaranteed to create a unique identifier, you could also use a [matrix-parameter](http://stackoverflow.com/questions/2048121/url-matrix-parameters-vs-request-parameters): `GET /people;firstName=John;lastName=Smith;birthday=1973-12-01` – Roman Vottner Jul 07 '15 at 15:53
3 Answers
5
I would use one of the following variations:
GET /people/John/Smith/1973-12-01
or
GET /people/John,Smith,1973-12-01

meskobalazs
- 15,741
- 2
- 40
- 63
1
As already mentioned in the comments, if you don't have a single identifier that ensure uniqueness, you could consider matrix variables:
GET /people;firstname=John;lastname=Smith;birthday=1973-12-01

cassiomolin
- 124,154
- 35
- 280
- 359