Take the 2-minute tour ×

I am designing a RESTful API. One Service should offer a query functionality for multiple key-value pairs. For example the Client can query with one HTTP GET request for different products and the belonging quantity.

Example: The Client wants to query product 1 with the amount 44 AND product 2 with the amount 55. So how can I design my URI for this case? I actually don't want my URI to look like, cause I don't know how many products are queried:


or like, because how can the client know, that before the comma there is the productId and after the comma the quantity:


Does anyone have got other solutions or isnt't it RESTful to offer the possibility to query multiple products with one request? Is it maybe better to offer the possibility to query just one product with the belonging quantity and if the client whants to query more products, he actually should send more requests...?

share|improve this question
what would be wrong with putting the query information into a http-post? –  schippi Dec 9 '12 at 15:38
@schippi Nothing, except that that wouldn't be RESTful :) –  dasblinkenlight Dec 9 '12 at 15:39
RESTful web services do not have to be exclusively based on GET. You could easily have a RESTful service that requires the transmission of more data than can be included in a GET request. It is reasonable to use any HTTP method. See: en.wikipedia.org/wiki/… –  Michael Dec 9 '12 at 15:47

2 Answers 2

up vote 1 down vote accepted

I would expand upon your second suggestion a little by adding explicit names for the parts of your product, and using semicolons in place of commas to separate product attributes, since the order does not matter*.


Note how id and qty are switched around for the second product, because the order of attributes does not matter.

* There is a convention to use commas when the order is important, and semicolons when the order is not important.

share|improve this answer
How can I inject those params into my REST Service? I know, I have to use the @QueryParam-Annotation, but how should I use this? –  joshi737 Dec 9 '12 at 17:05

here is a one idea pass parameter in manner like


where [{"key":"key0","value":"key1"},{"key":"key2","value":"key2"},{"key":"key3","value":"key3"}]

is a JSON representation of List<kv> class

class kv {
    String key;
    String value;

    public kv(String key, String value) {
        this.key = key;
        this.value = value;

    public String getKey() {
        return key;

    public void setKey(String key) {
        this.key = key;

    public String getValue() {
        return value;

    public void setValue(String value) {
        this.value = value;


so you can easily convert query parameter productDetail in to List<kv> using

new Gson().fromJson(productDetail,kv.class);

than you can easily iterate all elements.

other suggestion is if you dont know that how many products are queried than use POST request for this.

share|improve this answer
Like this idea, I would consider putting (query should be idempotent) the JSON, instead of using the GET query. –  Stefan Dec 9 '12 at 16:04

Your Answer


