Ruby Web Application Plumbing: Rack

Rack logo

There has been a proliferation of Ruby web application frameworks in recent times and this is mainly due to one thing; Rack.

Rack is a “Ruby webserver interface” that provides the plumbing for a Ruby web application framework to communicate with a webserver via an adapter. HTTP requests and responses are routed to the appropriate destinations with various niceties, like Apache-style logging, taken care of by Rack.

If your needs are simple, and a framework would be overkill, just use Rack on its own and code any little extras yourself. Visit the site for a list of frameworks that use Rack as well as a list of supported web servers.

I cannot stress this enough – if you are considering building YARWF (Yet Another Ruby Web Framework, pronounced ‘Yar-woof’) you need to be looking at Rack. It contains a lot of the basic infrastructure to get you started and is rapidly becoming a de facto standard in this space, even though it is only at release 0.3 at the time of writing.

To give you an idea of why people are excited about what Rack brings to the party, install Rack -

sudo gem install rack

Next, put the following in a file with a .rb suffix and run it -

taken from yeahnah.org

1 %w(rubygems rack).each { |dep| require dep } 
2 app = lambda { |env| [200, {}, 'Hello World!'] } 
3 Rack::Handler::Mongrel.run(app, :Port => 3000)

Yes that’s right, a working web app in 3 – count them – 3 lines of code.

There is a whole new Internet town growing up, filled with web houses that Rack built.

Permalink | comments(View)

blog comments powered by Disqus