What do you use Sinatra for? [closed]

烂漫一生 提交于 2019-12-03 05:27:15

Sinatra is not Rails. It is a micro-framework used for simple websites where you may need to just define a few actions. You can make a Sinatra application as complex as you want to, but you'll hit a point where you code has become a crazy mess sooner than with Rails.

While not 100% accurate, Sinatra fits mostly into the Page Controller architectural pattern, and Rails is a clear MVC implementation.

To answer your questions specifically:

  • It is not intended to replace Rails
  • It can run side by side
  • You could create a twitter clone in Sinatra

We're currently using Sinatra for a production project (not deployed live yet, still in dev).

Basically it's wrapping around a database used by a legacy app, and exposing REST web services to other apps internally so they can interact with the legacy app without having to access the DB directly.

Rails was considered, but not used because:

  • No view layer (essentially views are just JSON/XML REST responses)
  • Model is implemented using Sequel (ActiveRecord sucks dealing with legacy DBs with quirky, non-standard structures, but Sequel is quite nice for this)
  • Controller and routing layer is quite simple (although there is some complex business logic implemented in Ruby backing it)

Given these requirements Rails is usable, but overkill, where as Sinatra hits the spot nicely.

Take my answer with a bit of a grain of salt (because I haven't actually deployed a sinatra application before), but sinatra's "sweet spot" is micro-apps: tiny little applications where a full MVC framework would be overkill. With Sinatra, you can build an entire web app with a single file of code.

An example of a "micro app" is rubular (note, however, that I have no idea what framework it's written in). Rubular does one thing, and one thing very well. Using rails would be overkill.

We used Sinatra for http://tweetarium.com much like madlep's usecase the majority of the site is just AJAX calls, so the views are very simple.

We don't use an ORM, just serializing the JSON from the twitter API and caching it in TokyoCabinet

I personally think Sinatra is an excellent fit for APIs. Each version could be a different Sinatra app mounted at a different endpoint and you can run it inside of your Rails app.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!