REST API design for accepting as input a list of parameter values

3,791 views
Skip to first unread message

DK

unread,
Jul 25, 2012, 12:52:21 PM7/25/12
to api-...@googlegroups.com
Hi,

We have a requirement whereby our REST API requires a list of parameters:

For example get a Dog whose color is red, white and gold and its characteristics are happy, quite and calm. What is the best approach here?

GET            /dogs?colors=red,white,gold&characteristics=happy,quite,calm

Steve Klabnik

unread,
Jul 25, 2012, 1:30:57 PM7/25/12
to api-...@googlegroups.com
It may not be the BEST, but the Rails convention is to do

GET /dogs?colors[]=red&colors[]=white&colors[]=gold&characteristics[]=happy&characteristics[]=quite&characteristics[]=calm

The tooling automatically deserailzes this into arrays.

Your request is also valid, and would be another way of doing this
kind of thing.

Mike Kelly

unread,
Jul 25, 2012, 1:40:01 PM7/25/12
to api-...@googlegroups.com
It's worth noting that the key reason rails does it this way is that HTML forms can produce the URL via standard inputs (i.e. checkboxes). That's quite a nice capability to have, so it's usually the better option to go with.

Cheers,
M

DK

unread,
Jul 26, 2012, 5:35:38 AM7/26/12
to api-...@googlegroups.com
Thanks,

I found an alternative that I will use here: 

http://www.mkyong.com/webservices/jax-rs/jax-rs-queryparam-example/ 
Reply all
Reply to author
Forward
0 new messages