views:

53

answers:

2

I am writing a simple ruby controller that just needs to respond as a webservice to a bunch of mobile clients.

Someone told me I should look into Sinatra. What is the point of using Sinatra for something this simple? He mentioned that it would be "faster" but how can a wrapper on top of something make it faster?

I don't want to overcomplicate things; a simple controller is so easy to write and there are less gems to maintain. Am I missing something that Sinatra offers that makes it worth the extra trouble?

Thanks

+1  A: 

Sinatra is a very slim web framework. It needs way less memory at runtime than Rails. Also, request processing is probably faster since there's less code involved. So it can be very appropriate for a webservice "this simple".

Especially if you need to run many instances (e.g. high traffic or many long running requests), this can be an important factor to the number of machines you need to run your webservice.

Andreas
+1 Ah ok, thanks. So Sinatra is something I would run *instead* of rails. I was under the impression it was an additional wrapper on top of it.
cakeforcerberus
+1  A: 

The simplest useful Ruby web application you could build would be a Rack application. Sinatra is a lightweight DSL which sits on top of Rack to make coding the controllers and views more convenient. You can build more sophisticated applications by including more add-ons like ActiveRecord or Rack::Oauth, etc

Rails 2 is a more feature rich framework which includes a plethora of additional features already in the framework. Some applications don't need all that so some developers prefer things like Sinatra which is minimal.

However the distinction between Rails and Sinatra has blurred quite a bit since Rails 3. The new version allows everything from just Rack to full Rails in the stack to you can tailor it to suit your needs. The raison d'etre for some of the intermediate frameworks such as Sinatra is weaker than it used to be.

So take a look at Rails 3, start minimally and grow to suit your needs.

bjg
+1 thanks for the info
cakeforcerberus
specifically, the routing in Rails 3 allows you to define your middleware on a per route basis, so, you could use sinatra or rack directly for lightweight services, and Rails for more complicated services or requests.
Jed Schneider
So a website front end could be written in rails but the interfaces utilized by the mobile clients could be routed to a very thin Rack/Sinatra type app?
MattC