Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A simple router for Rack apps
branch: master
Failed to load latest commit information.
lib Made the request method part of the route
test Made the request method part of the route
.gitignore Added support for an optional format param based on the extension of …
.rvmrc Added support for named routes
Gemfile Basic gem skeleton
LICENSE Basic gem skeleton Improved the documentation by explaining how the parameter from the r…
Rakefile Added usage directly in the README
rack-router.gemspec Made the request method part of the route


A simple router for rack apps. Requires Ruby 1.9+.


Add this line to your application's Gemfile:

gem 'rack-router'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-router


Here's an example showing a simple rack app that prints the value of a route parameter:

require 'rack/router'
require 'rack/lobster'

hello = ->(env) do
    { "Content-Type" => "text/html" },
    ["<h1>Hello, #{env['rack.route_params'][:name]}</h1>"]

router = do
  get "/hello/:name" => hello
  get "/lobster" =>, :as => "lobster"

run router

In this example, hello is just a rack app defined inline, in order to give us something to route to. The route to our hello app includes a parameter :name. The hello rack app is able to access that parameter via the rack env.

This is a valid Rackup file, so if you put this in a file named and run rackup, you will be app to hit the application like this:

$ curl http://localhost:9292/hello/paul
<h1>Hello, paul</h1>

Don't forget to try the lobster!

$ open http://localhost:9292/lobster


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Something went wrong with that request. Please try again.