tags:

views:

274

answers:

4

Hi

For a REST interface:

What is the best way to allow the client to set many equally named parameters in a GET?

For example if the client should specify multiple possible colors

www.example.com/products/{color=green|color=yellow|color=white| ...}
+3  A: 

Something like this would be fine:

GET http://www.example.com/products?colors=green,yellow,white

Despite popular opinion, there is no REST constraint that says you should not use query string parameters.

Darrel Miller
From the looks of the question, query string parameters are appropriate. It appears to be a search request and that is what query parameters are for.
laz
A: 

if all you need is a simple query by a single parameter then I'd go with Darrel's suggestion, if your query can become more complex, you can consider SQL like query params:

GET http://www.example.com/products?query={colors IN (green,yellow,white) AND size='small')}
LiorH
Depending on your implementation, SQL injection could be a very likely problem with this solution.
Cloud
+1  A: 

Considering browsers consider the application/x-form-urlencoded and the querystring equivalent, and considering several values can be provided for the same name, you can simply do color=red&color=green&color&blue.

Provided your framework of choice handles this correctly, this should be jsut fine.

serialseb
A: 

For some queries, we could encounter URI length limitations. I'm curious how people have dealt with that in a RESTful fashion.

I was considering POST/PUTing a Query object with a document containing a large batch of query data, and getting the ID of that resource, then doing a GET operation, passing the query's ID.

Seems a bit less than optimal, though. Two queries, just to be RESTful.

msw10100