Skip to content

Provides a simple router & dispatcher for Rack applications as a Rack application.

License

Notifications You must be signed in to change notification settings

r7kamura/rack-multiplexer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

Provides a simple router & dispatcher for Rack applications as a Rack application.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages