1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

What is Sinatra?

By

Sinatra is a web framework. Simply put, it's a library that allows you to write web applications with a minimum of red tape. You simply load Sinatra, and start coding application logic. But this sounds awfully familiar, does it not? There are a lot of other web frameworks out there (especially in Ruby), so what makes Sinatra any different?

Instead of talking about what Sinatra is, let's talk about what Sinatra isn't. After all, the shortcomings of the other web frameworks out there is what prompted Blake Mizerany to create Sinatra in the first place. So here are a few of the things Sinatra isn't.

  • Big - Sinatra is tiny. Really tiny. Around 1500 lines of code. Rails is closer to 100,000 lines of code. That's almost 1/100th the size of Rails.

  • The answer to your problems - Sinatra doesn't solve any new problems. It doesn't do anything that Rails or other frameworks can't. It's just a web framework.

  • The right tool for every job - Other frameworks are the right tools for other job. Large-scale projects are better suited toward using something like Rails or Merb. Sinatra is suited for small-scale projects.

In the simplest of terms, Sintra is a minimal and elegant web framework. It doesn't include hundreds of helpers, or an ORM library (like ActiveRecord), or any complex wrappers on views. It prides itself in smallness, and this is reflected in your applications. Sinatra applications are often single file, including the views. Complete applications range in tens, sometimes hundreds of lines of code, including the views.

So what can you really use Sinatra for? Small web applications, for one. Rails is just too big to get out of its own way, sometimes you don't need all that. A small framework is a good fit for a small application. Another great use is services. Web services should provide simple, clearly-defined roles. This makes Rails overkill for services. This makes Sinatra justs right for services.

One final thing to touch on is that Sinatra is just Ruby. Yes, it is a DSL, but it's also just Ruby. You can use any Ruby libraries you want, and they're easy to plug in. Need models? Great, require ActiveDirectory and start using models. Want to output some XML? Very easy, just require Builder and have at it. There's nothing standing between you and code.

  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. Sinatra
  6. What is Sinatra?

©2014 About.com. All rights reserved.