6

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?

3
  • 2
    By 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. Commented Jul 7, 2015 at 15:15
  • 1
    This is a hypothetical example. Please operate under the assumption that firstName, lastName, and birthdate guarantee uniqueness. Commented Jul 7, 2015 at 15:21
  • 2
    I 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: GET /people;firstName=John;lastName=Smith;birthday=1973-12-01 Commented Jul 7, 2015 at 15:53

3 Answers 3

5

I would use one of the following variations:

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

or

GET /people/John,Smith,1973-12-01 
Sign up to request clarification or add additional context in comments.

Comments

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 

Comments

0

What about :

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.