Reputation: 510
I am trying to design my URLs so that I can get only one random resource of said type. What is the best route in going about this, query params?
/fruits/orange?search=random
Upvotes: 1
Views: 700
Reputation: 41287
Since there's no formal definition for REST URL designs, any answer to this is going to be quintessentially subjective. However, I tend to think that it's more consistent with RESTful URL patterns to server a random resource via a URL like this: /fruits/orange/random
(especially as I can't think of a query parameter key name that makes sense to use). However, in keeping with the whole idea of REST it would seem best that /fruits/orange/random
redirects the user to a specific entity, e.g., /fruits/orange/4129
.
Upvotes: 2
Reputation: 510
I decided to go with my query param idea for it is a variable in a an algoroithm. Random does not identify the resource at all so I do not want to map uris for it.
Also this will allow me to abstract my search algorithm for all resources with some AOP.
Upvotes: 0