When to Sinatra, when to Rails

On Rails, Sinatra, and picking the right tool for the job. Pedro Belo, of Heroku fame, finds Rails is way better for pure-web apps and Sinatra is way better for pure-API apps. Most of it comes down to Rails has better tooling and Sinatra is better for scratching itches, which happens a lot more in APIs than applications. I’m not ready to pronounce this the final word, but what he’s saying lines up with much of my experience.

That said, you can get pretty far with a Rails API by segregating it from your application. That is, your app controllers inherit from ApplicationController and your API controllers inherit from ApiController. This keeps the often wildly different needs of applications and APIs nice and distinct.

4 comments

  1. Marshall Yount · September 13, 2012

    Interesting discussion. Sadly, sufficiently complicated API projects can wind up dragging in pieces of Rails module by module.

    Kind of reminds me of this quote: “Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.”

  2. Adam Keys · September 13, 2012

    I see what you’re saying, but I’d love to know more. Which modules? Is it unavoidable, or as a shortcut?

  3. Marshall Yount · September 13, 2012

    ActiveSupport, ActiveRecord/Migrations (your mileage may vary), something for emails (but maybe not ActionMailer).

  4. Adam Keys · September 13, 2012

    Ahh, so all familiar things orthogonal to Sinatra. Into every application, dependencies must fall.

Comments are closed.