Getting Classy with Sinatra

I had heard about the Sinatra Ruby web DSL a while back but I had not had a chance to play with it until a few days ago. I’m happy to say it was a highly enjoyable experience. I accomplished what I was trying to do very quickly thanks to the good documentation and intuitive interface. It is not a replacement for MVC frameworks such as Rails, Merb, Ramaze, etc but it certainly compliments them.

Sinatra Features

The Sinatra README is a great resource for getting a run down of its features and I’m not going to regurgitate it here. However, I’d like to whet your appetite with a few of the features that caught my eye when I first scoped it out.

Rides on Rack

Sinatra rides on Rack and thus supports a wide variety of handlers such as: Thin, Mongrel, Phusion Passenger, etc (a full list is available on the Rack website). It can also be used to develop Rack middleware. More information about this is available on the README. If you’re interested in Rack middleware in general, Jon Crosby gave a great intro at the Moutain West Ruby Conf 2009.

Flexible Routing

The routing in Sinatra is powerful, supporting RESTful actions, named parameters, regular expressions, splats and user agents. See the Gist bellow for an example. The README page describes these options in more detail.

View/Template Support

There are a host of template options available when using Sinatra. Currently it supports HAML, ERB, Builder and SASS and automatic layout templates (provided you give it a “layout” template to work with). Again, checkout the README page for more details.

My Impressions

What struck me while I was working with Sinatra was how light it was and how out of the way it stayed. It was only present when I needed it to do something — outside of that, it let me build what I wanted, how I wanted. If Rails is the web developer’s assembly line then Sinatra is their essential toolkit — one drives you and the other is driven by you.

While having a pre-baked MVC web framework such as Rails and Merb is great, it does lock you in to one way of thinking about web development. With Sinatra you have the freedom to dabble and experiment — and I don’t think that can ever be a bad thing.

Resources

Here are some resources that I found to be useful in my first adventure with Sinatra.

pixelstats trackingpixel
  • Guest
    Hi, nice to meet you, my site provide DSL service, i hope you can get some information interesting in my site .
blog comments powered by Disqus