I am developing a media server, the basic functionality is to serve an image, which is done the following way


where :id is the id of the image.

You may want to ask for a specific size, with some rules I will provide.



Question: Which option do you think is better? I believe the second one to be more RESTful and beautiful, but we will be using a CDN and varnish for cache, so if we get




we will have 2 hits when we should have 1

Any advice?

  • Sounds to me like you can see the exact risk you take if you go with query string parameters, rather than a fixed path component. Now the question is, is that risk acceptable, or too high? – Sean McMillan Jul 16 '14 at 15:20
  • Using the query parameters suggests to me that ?height=49&width=51 would also be valid. The 50x50 path segment doesn't give this suggestion. How free are your users in choosing image size? – Bart van Ingen Schenau Jul 16 '14 at 15:55
  • @BartvanIngenSchenau they can choose whatever size they want in any of the 2 ways – amarseillan Jul 17 '14 at 16:46
  • @SeanMcMillan yep, wanted to see if someone had a solution because the correct way IMO is query string, maybe sorting the query string parameters in akamai and varnish – amarseillan Jul 17 '14 at 16:47
  • Matrix parameters are similar to query parameters but should result in a cacheable response. Maybe change query with matrix parameters? – Roman Vottner Feb 21 '16 at 0:57

According to URI standard the path should contain the hierarchical components and the query should contain the non-hierarchical components of the URI. But it can be subjective what is hierarchical and what non-hierarchical.

By developing a REST client these URLs mean nothing, because they follow hyperlinks and check link relations or other additional meta-data. (aka uniform interface / HATEOAS constraint)

If you cannot cache one of them, then you should choose the other one. Note: you always have to send cache headers. (aka cache constraint)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.