0.0
No commit activity in last 3 years
No release in over 3 years
Set up routes quickly and easily for a rack app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 2.12
= 0.6.2
= 3.2

Runtime

= 2.0.6
 Project Readme

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