Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST API Design with Composite ID

Tags:

rest

http

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?

like image 946
jwzirilli Avatar asked Jul 07 '15 15:07

jwzirilli


2 Answers

I would use one of the following variations:

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

or

GET /people/John,Smith,1973-12-01
like image 123
meskobalazs Avatar answered Sep 22 '22 17:09

meskobalazs


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
like image 42
cassiomolin Avatar answered Sep 23 '22 17:09

cassiomolin