8

From a RESTful point of view, what is the most appropriate HTTP method for the action of upvoting a forum post (like on StackExchange)?

I would say POST for voting and DELETE for canceling vote, but since users are only allowed to cast one vote per message, voting can be considered an idempotent operation so PUT can also be possible.

0

3 Answers 3

6

PUT /posts/323223/votes

A vote can be seen as an resource I would try that. I would not do any action agains the post (/posts/323223) since that is another resource. Then you would need to have an additional method and it starts getting complex.

7

I would argue you PUT your vote, or DELETE it. You don't actually edit the forum post, so POST would be inappropriate.

1

It mainly depends of what you consider to be your actual target object.

If your target object is the vote, then you should probably POST the vote to the system because you are actually changing the state of your target object (its internal vote counter).

Despite this, it is much more likely that you consider the forum post to be the target object of your operation and, in this case, most likely a PUT/DELETE operation set is more consistent with the REST phylosophy because you are not changing/editing your forum post. You are just putting/deleting a token into a counter. So, I would support the suggestion of Vain Fellowman.

The fact that voting should be an idempotent operation is another clue that should lead you in this direction. Think to this as a ADD/REMOVE operation over the "vote" member variable of your "forumPost" class/object.

Regarding how to tell if your real target object is the forum post or the vote, I think you should look at your code. The "object" (maybe a JSP page + a Java Controller + some Java Entity that refers to some DB table) that receives and handles this HTTP request is representing a forum post or a vote?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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