Channels ▼

Nick Plante

Dr. Dobb's Bloggers

Building Classy Micro Apps with Sinatra

March 26, 2009

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.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Dr. Dobb's TV