Generalized middleware implementation for Ruby.
Latest commit 23d4741 Jul 3, 2014 @mitchellh Merge pull request #11 from invisiblefunnel/fix-undefined-local-var
Fix reference to undefined local variable
Failed to load latest commit information.
lib Fix reference to undefined local variable Mar 26, 2013
spec Fix reference to undefined local variable Mar 26, 2013
.gitignore Initial commit Mar 16, 2012
.travis.yml Disable jruby 1.9 mode test because it was failing for dumb reasons Mar 16, 2012
.yardopts Add Mar 16, 2012
Gemfile Initial commit Mar 16, 2012
Rakefile Add default Rake task Mar 16, 2012
middleware.gemspec add MIT license metadata to gemspec Nov 8, 2013 Ruby colors in User guide Mar 16, 2012


Build Status

This is a generalized library for using middleware patterns within your Ruby projects.

To get started, the best place to look is the user guide.


This project is distributed as a RubyGem:

$ gem install middleware


Once you create a basic middleware, you can use the builder to have a nice DSL to build middleware stacks. Calling the middleware is simple, as well.

# Basic middleware that just prints the inbound and
# outbound steps.
class Trace
  def initialize(app, value)
    @app   = app
    @value = value

  def call(env)
    puts "--> #{@value}"
    puts "<-- #{@value}"

# Build the actual middleware stack which runs a sequence
# of slightly different versions of our middleware.
stack = do
  use Trace, "A"
  use Trace, "B"
  use Trace, "C"

# Run it!

And the output:

--> A
--> B
--> C
<-- C
<-- B
<-- A


  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