No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/rack
spec
.gitignore
Gemfile
Guardfile
README.md Update README Jun 15, 2015
Rakefile
rack-routing.gemspec

README.md

Rack Routing


Map URL routes to Ruby methods.

An example app is available at Rack Routing Demo.

Installation

Command line:
gem install rack-routing

Or add to your Gemfile:
gem rack-routing

Require the rack-routing file in an initializer:
require rack/routing

Example Routes

  1. GET / => get_root
  2. GET /foos/:id => get_foos (with @url_params)
  3. POST /foos => post_foos

Create a config/routes.txt file to set up the routes.

Example Requests

Request: POST /foos/bar

routes.txt: POST /foos/:value

The @url_params is set to { value: 'bar' }

The Ruby request handler might look like:

def post_foos
  Foo.create @url_params
  Rack::Response.new 'Foo was created.', 200
end

Here is a second example request:

 POST /foos, { "bar":"baz" }

Since this request uses body params, the @params is set to { baz: 'bar' }

The Ruby request handler might look like:

def post_foos
  Foo.create @params
  Rack::Response.new 'Foo was created.', 200
end

To run specs

rspec

or

bundle exec guard