Skip to content


Query strings in RESTFul web services

I said before that I don’t like query strings in RESTFul URIs. You cannot cache the results in the web server and in many cases they lead to a poor design of your URIs.

However, there are cases where query strings are useful and make sense. In the project I’m working right now, we have an asynchronous queue which several server instances consume periodically. This queue has events that must be processed, and each event belongs to a given user. Each user may have several events in the queue.

We have this queue of events that must be processed and we register them in another list when they are successfully processed. When an event is processed, he goes to the “processed” list if everything goes right or he stays in the queue if something gone wrong. In the queue we register how many times we tried to process each event.

In my team we have an application that helps us manage our infrastructure. This application does many things that we previously needed to ask to the operations team or DB team. Something very desirable is to be able to check how the queue is going without needing to check server logs or the database. So we’re adding some features in the management application to help us check the queue.

Ok, now let’s talk about the RESTful services. We’ve implemented some services that access the queue. One the of services allows us to check how many events are still in the queue with at least N tries. For example, how many events are pending with at least 1 try?

What’s the Resource here? In my opinion the resource is “Pending event”. Considering this, I would access this resource doing GET /event/pending. Ok, but doing GET /event/pending would probably give us the whole list of pending events. I want pending events with at least 1 try. How can we do that? We could do a GET /event/pending/1, and it would work. However, this URI is bad, very bad. If I didn’t know what this service was about, I’d probably say this URI returns the first pending event according to some order. Probably it would be the oldest or newest one.

So how do we form this URI? We could also have a GET /event/pending/tries/1. This would indeed be much better than the first URI, but I don’t like it either. My resource is “Pending event”. Pending events with at least 1 try are still just pending events for me. What I want is just to filter the pending events. So, I ended up using GET /event/pending?t=1. “t” in this query string stands for “tries”. I could also have used GET /event/pending?tries=1. As a matter of fact, I think supporting both is nice. It would be similar to command line options in Unix applications.

Now, let’s say I want to know the pending events of a given user. Looking at the previous URI, You might say GET /event/pending?u=123 or GET /event/pending?user=123. But in this case, I wouldn’t use query strings. The best URI in my opinion is /event/pending/user, and that would lead to GET /event/pending/user/123. What’s the difference here? I consider the “User” as a meaningful thing. It’s another resource. However, “number of tries” for me is just a filter. I don’t need to know anything about a specific try, so it’s just a filter in this case. Another similiar filter would be “Pending events created before today”. We could have another query string parameter to filter events by creation date. Something like GET /event/pending?c=03/04/2008 or GET /event/pending?creation=03/04/2008.

So, I changed my mind a little bit about query strings. They are indeed useful in some cases, such as this example. They are good to filter results. Filter by something that it’s not a resource. To decide our URIs we must always think of what’s really a resource in our application, and what’s just a filter. Such as in the world wide web, URIs identify Resources. After deciding what’s a resource and what’s just a filter, we can design our URIs much better. Meaningful URIs are among the most important things in RESTFul web services.

Posted in posts em português.

Tagged with , , .


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Alexandre Bairos says

    A nice match seems to be: Filtering and Value types(String,int,long,Date) as query strings and domain associations as URI. /event/pending?from=20080706&to=20080901 , /event/pending/user/123 , /event/pending/user/operation?mostRecent=true&n=5

  2. blpsilva says

    Yep, that’s pretty much what i think right now. It’s very nice the fact that we’re both working with RESTFul services, because our understanding of the problem grows much faster with the continued discussions :)



Some HTML is OK

or, reply to this post via trackback.



  • Buy Cheap xanax recreational use Now The Largest Internet Pharmacy. Best Online.
  • Buy Cheapest insomnia medication prescription Online Drugs, Health And Beauty. Best Internet.
  • Buy Cheapest drugs online Now Low Prices. Discount Pharmacy Online.
  • Buy Cheap pharmacies and prescriptions for pain meds Online No Prescription Needed. Best Prices.
  • Buy Cheapest buy depo medrol Online Best Prices. Internet Prices For buy depo medrol!
  • Buy Cheapest names of prescription pain medications Now Best Drugstore. Cheap Online Pharmacy.
  • Buy Cheapest cialis profestional Online Online Medical Shop. Pharmacy Store.
  • Buy Cheap buy cialis cialas Online Best Drugstore. Online Medical Shop.
  • Buy Cheap health med Now 100% Satisfaction Guaranteed. Pharmacy Store.
  • Buy Cheap on line pharmacies Online Online Prices For on line pharmacies! Best Prices.
  • Buy Cheap consumer proven weight loss medication Online Discount Online Pharmacy. Best Internet.
  • Buy Cheap drugs to treat depression Online Special Prices For drugs to treat depression! Best Online.
  • Buy Cheap medicin depression buy Online 24/Internet)(safe Pharmacy. Best Prices.
  • Buy Cheapest antidepressant purchase france Now Pharmacy At The Best Price! Best Online.
  • alprazolam overdose Online Without Prescription Free Viagra Pills! Best Prices.
  • Buy Cheapest cialis free trials Online Best Internet. WorldWide Shipping.
  • Buy Cheapest belly fat diet pill Online Best Online. Online Prices For belly fat diet pill!
  • Buy Cheapest prescription drugs on internet Online Discount Pharmacy Online. Best Online.
  • Buy Cheapest cheap overseas pharmacies Now Pharmacy At The Best Price! Best Online.
  • Buy ambien purchase Without Prescription Doctor. Pharmacy Store. Low Prices.
  • Buy Cheap spain farmacia levitra Online Online Medical Shop. Cheap Online Pharmacy.
  • Buy Cheapest what is viagra super active Now Top Online Pharmacy. Cheap Pharmacy Online.
  • Buy Cheap overdose of xanax Online Online Medical Shop. Pharmacy Store.
  • Buy Cheap impotence drugs Online Best Online. Internet Prices For impotence drugs!
  • Buy Cheap buy narcotic pain relievers Now Discount Online Pharmacy. WorldWide Shipping.
  • Buy Cheapest phentermine online without doctor orders Now Pharmacy Store. Buy Medications Online.
  • Buy Cheapest generic name viagra Now Pharmacy At The Best Price! Pharmacy Store.
  • Buy Cheapest cheap priced valium Online Guaranteed Shipping. Pharmacy Store.
  • Buy Cheapest buy sleep aids on line Online Best Prices. Discount Online Pharmacy.
  • Buy Cheap viagra drug interactions Online Guaranteed Shipping. WorldWide Shipping.
  • Buy Cheap cheap sarafem Now The Largest Internet Pharmacy. Best Online.
  • Buy Cheap phentermine 30mg Now Cheap Meds Without Prescription. Best Online.
  • Buy Cheap valium dosage Now Guaranteed Shipping. Online Prices For valium dosage!
  • Buy Cheap pain pill withdrawals Online No Prescription Needed. Best Online.
  • Buy Cheap cialis for erection Now Special Prices For cialis for erection! Best Internet.
  • Buy Cheap weight loss doctor online Now Bonus Pills And Reorder Discounts! Low Prices.
  • Buy Cheapest levitra website Online Guaranteed Shipping. Pharmacy Store.
  • Buy Cheap free samples cialis Online Best Internet. Cheap Prescription Drugs.
  • Buy Cheapest maximum fat loss Online WorldWide Shipping. Pharmacy Store.
  • Buy Cheap tadalafil jelly Online Discount Online Pharmacy. Best Prices.
  • how to buy impotence medication Online Without Prescription Best Drugstore. Low Prices.
  • Buy Cheap prescription weight loss meds online Now Guaranteed Shipping. Top Online Pharmacy.
  • Buy Cheapest cheap femara Online Pharmacy Store. No Prescription Needed.
  • Buy Cheap viagra size Online Best Online. Top Online Pharmacy Supplier.
  • Buy Cheap vardenafil hcl Online Pharmacy At The Best Price! Best Drugstore.
  • Buy Cheapest prescription for chlamydia Now Free Viagra Pills! Cheap Pharmacy Online.
  • Buy Cheapest cialis flagstaff Online Free Viagra Pills! Pharmacy Store.
  • Buy Cheapest valium generic Online Guaranteed Shipping. Best Online.
  • Buy Cheapest cheap diet pills online Now Best Online. Online Prices For cheap diet pills online!
  • Buy Cheapest weight loss medicine buy online Now We Can Offer You Visit Our Online Pharmacy.
  • Buy Cheap curing impotence Online Order Cheap Meds Without Rx. Best Online.
  • Buy Cheapest stronger pain killer Now Free Viagra Pills! No Prescription Needed.
  • Buying Cheap india pharmacy. Offshore Rx, Good Prices. Guaranteed Shipping.
  • Buy Cheapest order ampicillin Now Internet Prices For order ampicillin! Best Drugstore.
  • Buy order quality cialis Online Without Prescription. Best Online. Low Prices.
  • Buy Cheap accutane before after Now No Prescription Needed For Drugs. Best Prices.
  • Buy Cheapest side effects of ambien 10 mg Online Cheap Pharmacy Online. Low Prices.
  • Buy Cheapest original cialis Now No Prescription Needed. Free Viagra Pills!
  • Buy Cheapest xanax 2 mg no prescription Now Top Online Pharmacy. WorldWide Shipping.
  • Buy does zyban work Online Without Prescription. Pharmacy Store. Low Prices.
  • Buy Cheapest viagra alcohol Now Special Prices For viagra alcohol! Best Drugstore.
  • Buy Cheapest lexapro for anxiety Online 24/Online Pharmacy. Low Prices.
  • Buy Cheapest viagra for recreational use Now Buy Medications Online. WorldWide Shipping.
  • Buy Cheapest diazepam us pharmacy Online Drugs, Health And Beauty. Low Prices.
  • Buy Cheap how to take viagra Now 24/Online Pharmacy. WorldWide Shipping.
  • Buy Cheapest viagra canada satisfaction guarantee Online Drugs, Health And Beauty. Best Internet.
  • Buy Cheapest mexican cialis Online Drugs, Health And Beauty. Best Internet.
  • Buy Cheapest drug ambien Now Cheap Pharmacy Online. WorldWide Shipping.
  • Buy Cheapest prescribed weight loss medication Now Free Viagra Pills! Cheap Pharmacy Online.
  • Buy Cheap best price for cialis Online Internet Prices For best price for cialis! Low Prices.
  • Buy Cheapest levitra pill size Online Low Prices. Buy Medications Online.
  • Buy cvs drug stores Without Prescription Doctor. Low Prices. Best Internet.
  • Buy Cheap promethazine tablets Now Best Online. Safe And Secure Payment System.
  • Buy Cheap online consultation xanax Online Pharmacy Store. Top Online Pharmacy.
  • Buy Cheap lorazepam withdrawal symptoms Online Best Prices. Drugs, Health And Beauty.
  • Buy Cheapest ultram ultracet Online No Prescription Needed. Low Prices.
  • Buy Cheapest fast weight loss Now Best Online. 100% Satisfaction Guaranteed.
  • Buy Cheapest drugs for depression Now Best Internet. Buy Medications Online.
  • Buy Cheapest valium recreational Online Best Online. Online Prices For valium recreational!
  • Buy Cheapest cialis low dose Now Buy Medications Online. Free Viagra Pills!
  • Buy Cheapest otc treatment for scabies Now WorldWide Shipping. Online Medical Shop.
  • Buy Cheapest diazepam mylan Now Cheap Pharmacy Online. Best Drugstore.
  • Buy Cheap cheap phentermine 37.5 Now The Largest Internet Pharmacy. Best Drugstore.
  • Buy Cheapest pain pills online thailand Online Best Drugstore. Cheap Pharmacy Online.
  • Buy Cheapest prescription drug store online Online Best Internet. Discount Pharmacy Online.
  • Buy Cheap over the counter weight loss drugs Now WorldWide Shipping. Cheap Online Pharmacy.
  • Buy Cheap klonopin effects Now Top Online Pharmacy Supplier. Low Prices.
  • Buy Cheapest erectile dysfunction syndrome drugs Online Best Online. Cheap Prescription Drugs.
  • Buy Cheapest buy ambien online without prescription Online Buy %items% Online Without Prescription.
  • Buy Cheapest viagra online overnight delivery Online Best Drugstore. Online Medical Shop.
  • Buy Cheap bayer levitra cheapest price online pharmacy Now Special Prices For bayer levitra cheapest price online pharmacy! Best Online.
  • Buy Cheapest indian tadalafil Now Best Prices. Cheap Prescription Drugs.
  • Buy Cheapest accutane before after Now Best Online. Pharmacy At The Best Price!
  • Buy Cheapest reliable online pharmacy Now Pharmacy At The Best Price! Best Online.
  • Buy Cheapest finasteride tablets Online Cheap Pharmacy Online. Low Prices.
  • Buy Cheap list pain meds Online Top Online Pharmacy. WorldWide Shipping.
  • Buy Cheap tramadol medicine online Online Internet Prices For tramadol medicine online! Best Internet.
  • Buy Cheapest cialis coupons Online Best Internet. Cheap Prescription Drugs.
  • Buy Cheapest cialis professional cheap Now Cheap Prescription Drugs. Best Drugstore.
  • Buy Cheapest online canada pharmacy Online Free Viagra Pills! Best Drugstore.