Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Simply Restful

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
  1. create a new message response = http.post(”/messages”, ”...”)
  1. retrieve message #1 response = http.get(”/message/1”)
  1. update an existing message response = http.put(”/message/1”, ”...”)
  1. delete an existing message response = http.delete(”/message/1”)

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly