REST API URI for resource with multiple primary keys

angro picture angro · Jun 4, 2016 · Viewed 7.2k times · Source

I am developing a generic REST API for my projects and I'm wondering what to do when I have a table/resource with 2 or more primary keys.

For example, lets suppose I have a table named "question" with two primary keys (date and type) and I need to create the resource REST URI. What is the best way to do it following the standard schema api/{resource}/{id}?

Maybe something like: api/question/{:date},{:type}? What is the best way to do it?

Thank you.

Answer

Alexandru Marculescu picture Alexandru Marculescu · Jun 4, 2016

You're on the right path, I think you definitely should include both the date and the type in the resource url if that's the only way you can uniquely identify it

api/question/{date}_{type}