If you are in the Ruby world you have probably heard of Rack. If you haven’t, and you are a Pythonista, then you only need to know that Rack is a sort of “WSGI for Ruby”. And in case you don’t know what Rack or WSGI are, then here’s a brief description:
“Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.”
Creating a Rack Middleware
Rack Middleware’s interface is dead simple. As Marc-André Cournoyer points out: “It must have a call method and receive a Rack app as the first argument of new”.
Running your application with middleware
This is also really simple using Rack::Builder:
So here is an example of a rackup file that you can use to startup your application with some middleware:
Testing and Spec’ing helpers
Where to go from here
To learn how to develop your own Rack Middleware, your best resource will be Rack sources. You will learn a lot of Rack (and Ruby in general) by reading the code and specs they provide: URLMap, CommonLogger, File. There also is a group where you can ask your questions too.
So enjoy your trip with Rack Middleware and feel free to comment your thoughts and questions!