Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

/media/:id

where :id is the id of the image.

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

Eg:

/media/:id/50x50
/media/:id?witdh=50&height=50

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

/media/:id?width=50&height=50

or

/media/:id?height=50&width=50

we will have 2 hits when we should have 1

Any advice?

share|improve this question
    
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

1 Answer 1

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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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