[uf-rest] Fwd: REST and Rails

David Heinemeier Hansson david at loudthinking.com
Sun Apr 16 10:51:32 PDT 2006

Hi guys,

Just wanted to let you know that we've been very inspired by the  
thoughts on this list and elsewhere about better RESTing in Rails.  
We've just added verb support for Routing (http://dev.rubyonrails.org/ 
changeset/4209) and are currently exploring a very simple name- 
convention based approach to dispatching verbs to controllers in the  
Simply Restful plugin: http://svn.jamisbuck.org/rails-plugins/ 

Here's the README for that plugin:


SimplyRestful is a plugin for implementing verb-oriented controllers.  
This is
useful for implementing REST API's, where a single resource has  
behavior based on the verb (method) used to access it.

Giving credit where credit is due, this idea was inspired by reading:


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,

For example:

   class MessagesController < ActionController::Base
     def index
       # return all messages

     def create
       # create a new message

     def show
       # find and return a specific message

     def update
       # find and update a specific message

     def delete
       # delete a specific message

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")

     # create a new message
     response = http.post("/messages", "...")

     # retrieve message #1
     response = http.get("/message/1")

     # update an existing message
     response = http.put("/message/1", "...")

     # delete an existing message
     response = http.delete("/message/1")

David Heinemeier Hansson
http://www.37signals.com    -- Basecamp, Backpack, Writeboard, Tada
http://www.rubyonrails.com  -- Web-application framework
http://www.loudthinking.com -- Broadcasting Brain

More information about the microformats-rest mailing list