Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The query string can still be used in REST web services just not in the same way as normal.</p> <p>You have to think of the URL as the <em>key</em> to a resource. The URL is an unique identifier for the resource. For example</p> <pre><code>http://example.com/products/123 -- where 123 is the id of the products. </code></pre> <p>Accessing to <code>/products</code> would return a full list of products. Adding the id would return a specific product.</p> <hr> <h3>The problem with using slashes for every filter</h3> <p>What if you want to order product in a specific way? Some would say </p> <pre><code>http://example.com/products/united-states </code></pre> <p>Well, now there is some ambiguity at the first look. Is united-states an id? Well that ambiguity can be solved by saying an id is represented as <code>\d+</code>. Correct.</p> <p>Ok so our first parameters which is made of words is a country.</p> <p>Now lets say we want to add more filters, lets try and add more slashes.</p> <pre><code>http://example.com/products/united-states/home/asc </code></pre> <p>But I don't want united states products only! But still want home products.</p> <pre><code>http://example.com/products/home/asc </code></pre> <p>Wait... is home a country? I'm not sure now, it's kind of ambiguous... And what if I want to add another filter tomorrow? What will I do... add more slashes?</p> <p>The URL becomes cluttered and full of ambiguous parameters that were optional at first and that become obligatory because of ambiguity.</p> <hr> <h3>My advice</h3> <p>The correct way, to me, would be to use the <strong>query string</strong> for thing specific about the query. Because, I can sort the query in any way I want, it is still the same query. I query products.</p> <p>So the form should be like</p> <pre><code>http://example.com/products -- all products http://example.com/products/{id} -- specific one http://example.com/products/?country=united-sites -- filtered </code></pre> <p>This way you can add new filters anytime you want and keep URLs that are clear and won't ever break even though you change the filters.</p> <hr> <h3>More information</h3> <p>If you want more information I really, really advise you to <strong>look at <a href="http://www.youtube.com/watch?feature=player_embedded&amp;v=NEWTPFzt2-E">this conference</a></strong> by David Zülke, a guy working for the Symfony framework. He talks about a lot of things of REST web-services, but he also talk specifically about URLs, and how to build them <em>(Mainly from 16 to 30 minutes)</em>.</p> <p>You can also look at <strong><a href="http://apigee.com/about/api-best-practices">apigee website</a></strong>. They have a lot of videos (and books) about REST. More specifically <a href="http://apigee.com/about/api-best-practices/restful-api-design-second-edition">this video</a>, which is really on topic here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload