In my continuing quest to try and wrap my mind around RESTful-ness, I’ve come to another place where I’m not sure how to proceed. I set up a thought expiriment for myself where I’d design a simple voting system for a resource, much like how SO allows voting on questions. So, say my resource is an image, and I can get an image by an ID, like so:
http://www.mysite.com/images/123123
And in this example, that returns say, a JSON representation of an image, like so:
{ 'URL':'http://www.mysite.com/images/123123.jpg', 'Rep':'100' }
How would I design a way to ‘vote’ on that image? I’d like two operations; up-vote and down-vote. The client shouldn’t know how much weight each carries, because I’d like to have the award for an up-vote/down-vote be decided at the server level so I can change it anytime I like.
My first idea was to have something like this:
http://www.mysite.com/vote/images?image=123123
To that URL, one could POST something like the following:
{ 'Vote':'UpVote' }
But I’m wary of that – to me that says RPC in disguise. Would that be a poor way to design this? If so, what other designs could I try?
To be restful you should return something like this
As far as REST is concerned it doesn’t matter what the format of the links are. As long as your client knows that it is supposed to do POST to the ‘UpVoteLink’ or ‘DownVoteLink’ it couldn’t care less what the format of the URL is.
Also, if you decide in two weeks that you don’t like the URLs you picked, you can change them and no-one will care!
Ok, ok, if you really want a suggestion for an url design, how about
What is cool about this design is that you could vote on images that are not even on your site!