by hayksaakian · 13y ago · 0 comments
When do I use Sinatra?
It takes care of a lot of unknowns for a lot of people. For instance, it makes sure you do proper redirects. Did you know that IE9 implements 302 like 307 but only for redirects from Ajax? But you can't simply use 303 as some HTTP clients don't properly implement it? Rack does not care about such things.
It also comes with built-in security, which Rack does not.
If you are comfortable with Rails and it suits your needs (that is, a monolithic model driven application), stick with it, there is nothing wrong with Rails.
Sinatra is good for APIs but it's easy to find yourself reinventing Rails/Padrino when you have a view layer.
You can use Sinatra for the same things that you use Rails for, but typical use cases are API's, since there's a lot of stuff in Rails that you don't want to use if your main output isn't html.
And for REST endpoints.
The light part means: it doesn't drag a huge framework and code and complexity you don't need with it. It uses less resources than it would if it was doing that.
Our API app used to be a Rails application, but we ended up writing our own object serializers etc, so that the controllers were actually more or less just calling out to one method.
When we reworked our API, authentication, etc, we switched over to Sinatra.