Simply Restful plugin

Plugin details

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.

Websitehttp://pezra.barelyenough.org/blog/2006/03/another-rest-controller-for-rails/ Repositoryhttp://svn.jamisbuck.org/rails-plugins/simply_restful/ Tags Rest LicenseRuby's (MIT)

Documentation

Install the plugin:
ruby script/plugin install http://svn.jamisbuck.org/rails-plugins/simply_restful/

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

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

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

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 9 months ago