I'm having trouble setting up proper routing for an application for
ranking photos. My major gripe is how to properly map methods that apply
for a resource, such as voting.
The basic routes are
/photos - List of photos, goes to PhotosResource
/photos/{photoID} - Show the photo, goes to PhotoResource
Now the problem would be how to properly say that /photos/{photoID}
should receive a vote. One candidate is:
/photos/{photoID}/vote
This would then be something you POST a vote to. Most likely this looks
like something that would be handled by a PhotoVoteResource but is there
any (reasonable) way that I can let PhotoResource handle it? It feels
kind of strange that I would create a bunch of Resource classes to handle
/photos/{photoID} - PhotoResource
/photos/{photoID}/vote - PhotoVoteResource
/photos/{photoID}/votes - PhotoVotesResource
/photos/{photoID}/comment - PhotoCommentResource
/photos/{photoID}/comments - PhotoCommentsResource
... and so on for all methods I want to apply for a photo.
Doing something like /photos/{photoID}/{method} and setting that up to
PhotoResource looks kind of scary. Then I would have to do alot of
checking in represent() or acceptRepresentation() to see which method to
apply. /photos/{photoID}/vote should only accept a POST, but since it
uses PhotoResource I must also be able to handle GETs (via
/photos/{photoID}).
There must be some other approach to this? What is recommended?