Building Classy Micro Apps with Sinatra
I first wrote about Sinatra, the lightweight Ruby web microframework, back in my very first post for DDJ Code Talk, mentioning it in brief as a young alternative to Rails for lightweight microapps. Since then, Sinatra has matured significantly, and is quickly becoming the leading alternative to Rails for Ruby-based web applications that don't need all the extra overhead.
Anyway, I gave an introductory Sinatra talk and taught a hands-on live coding session at a user group earlier this month, so I thought I'd recycle it for my readers here. It should quickly familiarize you with Sinatra's purpose and limited syntax: A Quick Introduction to Sinatra (NH Ruby) (click to view)
Want to see some real world applications using Sinatra? There are plenty. In addition, Sinatra's creator, Blake Mizerany, and one of its primary developers, Ryan Tomayko, are now both gainfully employed by Heroku, who has been using the framework in a number of ways throughout their architecture. Other pioneering web destinations like GitHub and Songbird are also making use of it. It's ideal for creating web service APIs and micro applications, among other things.
I've used Sinatra for a few public projects myself, most recently the single-page Twitter dream journal application tweetdreams. The source for tweetdreams is available on GitHub (minus the custom theme). Check it out, take a quick tour through the source, and see what you think. Clearly, this isn't a large application, but it demonstrates how you can get from A to B with Sinatra for this simple purpose. There's also code available for a slightly more complex (but still very simple) IRC pastebin service.
Personally I really like the Sinatra approach; it's really more of a minimalist RESTful DSL for building web apps than it is a proper full-featured framework, and it's up to you to make your choice of ORM, JavaScript libraries, testing framework, and so on. I often find that I don't need all the extras (or defaults) provided by a framework like Rails, particularly when I'm building something of limited scope. For this class of web app, Sinatra is a really classy option.

