public
Description: A tiny module that aims to provide a REST-like interface to any Ruby object
Homepage: http://yapok.org/
Clone URL: git://github.com/madx/rackable.git
Click here to lend your support to: rackable and make a donation at www.pledgie.com !
name age message
file LICENSE Sun Jul 19 09:40:40 -0700 2009 add the MIT license [madx]
file README.md Sun Jul 19 09:39:06 -0700 2009 more examples [madx]
directory examples/ Mon Jul 20 00:32:15 -0700 2009 add RestArray example [madx]
file rackable.rb Tue Jul 28 06:12:21 -0700 2009 allow the called method to modify the response ... [madx]
README.md

Rackable

Rackable is a tiny module that aims to make any Ruby object Rack-friendly and provide it with a REST-like interface.

Basically, what it does is providing an object with a call() method that uses the Rack environement to dispatch to a method, giving helper objects such as headers, query parameters, ...

Specs

You can run the specs by running bacon on the rackable.rb file. Bacon is available at chneukirchen/bacon

Examples

Look in the examples/ folder.

Docs

Rackable provides a rack readable attribute which is a struct containing the following fields:

  • env: the parameter for call
  • response: a Rack::Response object that is returned by call
  • header: a hash of headers that is part of response
  • request: a Rack::Request created from the environement given to call
  • query: a hash of parameters extracted from the query string
  • data: a hash of parameters extracted from the request body (POST, PUT)

For both query and data, keys of the hash are symbols.

You can easily handle errors with the provided http_error method. It takes an error code and an optional message. If no message is given, the standard message from the HTTP Status Codes list will be used (eg. Not Found for 404)