Rack::Multiplexer
Note
This project is archived because I no longer actively use it, and there seems to be no recent activity from other users either. If you are still using it and would like to take over maintenance, please contact me somewhere.
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 multiplexerDSL
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
}