You are here: Browse Railsplugins Simply Restful
SimplyRestful is a plugin for implementing verb-oriented controllers. This is useful for implementing REST API’s, where a single resource has different behavior based on the verb (method) used to access it.
Giving credit where credit is due, this idea was inspired by reading:
http://pezra.barelyenough.org/blog/2006/03/another-rest-controller-for-rails/
Because browsers don’t yet support any verbs except GET and POST, you can send a parameter named “_method” and the plugin will use that as the request method, instead.
For example:
class MessagesController < ActionController::Base
def index
# return all messages
end
end
def create
# create a new message
end
def show
# find and return a specific message
end
def update
# find and update a specific message
end
def delete
# delete a specific message
end
Your routes would be something like:
map.resource :message
Then (using Net::HTTP to demonstrate the different verbs):
Net::HTTP.start("localhost", 3000) do |http|
# retrieve all messages
response = http.get("/messages")
end
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly