0.01
No commit activity in last 3 years
No release in over 3 years
Provides a simple router & dispatcher for Rack.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.2.14
~> 1.3
>= 0
>= 0
= 2.14.1

Runtime

>= 0
 Project Readme

Rack::Multiplexer

Provides a simple router & dispatcher for Rack applications as a Rack application.
The routing algorithm has only O(1) time complexity in Ruby level because all routes are compiled into one Regexp.

Installation

gem install rack-multiplexer

Usage

For rackup.

# config.ru
require "rack-multiplexer"

multiplexer = Rack::Multiplexer.new
multiplexer.get("/a", ->(env) { [200, {}, ["a"]] })
multiplexer.get("/b", ->(env) { [200, {}, ["b"]] })
multiplexer.put("/c", ->(env) { [200, {}, ["c"]] })
multiplexer.get("/d/:e", ->(env) { [200, {}, [env["rack.request.query_hash"]["e"]]] })

run multiplexer

DSL

The block is with you, always.

# config.ru
require "rack-multiplexer"

run Rack::Multiplexer.new {
  get "/a" do
    [200, {}, ["a"]]
  end

  get "/b/:c" do
    [200, {}, ["d"]]
  end
}