However, if it's possible your app could grow beyond simply returning JSON responses ex: render HTML content, have interactive forms, users sessions, etc you can rule out Grape.
Thanks to Rack's support for mounting apps, you aren't stuck with a rewrite if the scope of your app changes and your chosen microframework begins to get outside its sweet spot. You can easily mount Grape and Sinatra apps within a Rails app, or even mount a Grape app alongside a Sinatra app. Grape emerges as a clear choice when you outgrow a roll-your-own approach to an API. The conventions it covers make it easier for a team of developers to have a clear understanding of best practices that don't exist in custom API apps.
I'd view these with some caution: Rails::API still contains a significant amount of middlewares that may be required in a production Sinatra or Grape app. These middlewares add overhead. Want more Ruby insights like this delivered monthly to your inbox? Just put your email into the sidebar form. Adding servers can be a band-aid for slow code. Scout APM helps you find and fix your inefficient and costly code. Ready to optimize your site? Sign up for a free trial. All Engineering Performance Community.
Rails::API vs. Writing in Sinatra can give developers and businesses API stability because the framework rarely changes.
You own your code and you decide when it should change. He goes on to say that Sinatra is the perfect candidate when it comes to building an application:. Sinatra fulfills all I need for a base platform and anything else I need I can either use gems or is already provided by cloud platforms and services like Heroku and its eco-system of add-ons.
Anything else left over I can write it myself. In fact, this idea could be taken a step further by using Sinatra to roll your own bespoke framework that fits your needs perfectly. Start with Sinatra and then add in the gems that provide the features you need in order to create your own bespoke framework. In some ways, this is what the Padrino project has done.
Breaking everything into tiny little pieces and having developers assemble everything on their own is the antithesis of what Rails is all about and how it won the framework game. Tens of thousands of man hours have gone into getting us to this point.
But while having more control over what goes into your app might be a nice idea, Konstantin Haase warns that this could take up a lot of your time:. The biggest disadvantage with Sinatra not solving the issue for you is, well, Sinatra not solving the issue for you. You actually have to deal with that issue. You might end up wasting too much time dealing with it. And this is time that the developers simply may not have at their disposal if they are working to a tight budget.
David Heinemeier Hansson is concerned that using Sinatra involves wasting so much time trying to reinvent the wheel:. I pity the person who would try to build all of Basecamp, GitHub, Shopify, or any other major app in Sinatra alone. Rails is involved and large because it contains solutions to most of the problems that most people building apps of such scale will encounter. Trying to recreate all these solutions by hand is the anti-simplicity.
Ryan Bates, presenter of Railcasts feels that an advantage of using Rails is the amount of time that is saved when starting a project from scratch:. The default Rails app provides a lot that I need which requires extra setup in Sinatra. This can lead to faster development in Rails. This sentiment is echoed by Rick Olson who believes that Rails made it easy to get GitHub off the ground:. I think Rails was a major asset to the founders [of GitHub] in the first year.
They were able to take advantage of some of the higher level Rails features and iterate quickly. The problem is that these conventions can sometimes feel like a straight jacket at times as Rick Olson points out:. In contrast, Sinatra, has no restrictions whatsoever, as illustrated by this great quote from Aaron Quint provided by Satish Talim of Ruby Learning :. WDNNSP means that Sinatra is beyond flexible, and it contains no preconceptions of how you organize your domain or business logic.
It has no implicit folder structure, no default Database Abstractor, and no restrictions about how or where you use it. A lot of the appeal with Sinatra is being able to choose how your app is structured in every way.
Using Sinatra can be liberating, as you are not restrained by size, structure or work flow. You can build an API, web application or pack your code up as a gem. We considered adding a single-file mode to Rails but rejected it because why would we want to optimize for something Sinatra already does so well? Rails 3 tries to mitigate this as much as possible by decoupling some of the different features, which can lead to a lighter and more confgurable exerience, as Chad Fowler points out:.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Sinatra vs. Rails Ask Question. Asked 11 years ago. Active 1 year, 8 months ago. Viewed 23k times. Add a comment. Active Oldest Votes.
Sergio Tulentsev k 40 40 gold badges silver badges bronze badges. Thanks for the info. I assume it's possible to just use ruby commands to start the webrick on a certain port and point it at a certain directory?
I just Googled for "webrick", 3rd result: microjet. I don't see why you want to bother with all that though honestly, seems pretty pointless, and Webrick isn't exactly the best server. You can ignore all the other features, or use them later if you wish. Did you see the hello world for Sinatra? I think I'm going with Sinatra for this project. And thanks for the links! So, when the best to use Rails? You need fast development time. Just follow the convention; The future features of your apps are still unknown.
When the best to use Sinatra? You don't need fast development time; Sinatra can be fast if you only work in mini project; You know that you won't add many features in the future. What do you gain from Rails?
0コメント