Why You Should Use Hanami, and Why You Might Need (Yet) Another Ruby Framework

As we pointed out in the very beginning of this article, Hanami is just one of several Ruby frameworks.

Ruby on Rails is the most popular of the Ruby frameworks. It’s very modular and general purpose. It could be said that it’s main promise is that you can use it to go from zero to having a working app prototype in a matter of hours.

Then there’s the less popular, but no less powerful Sinatra? What’s it’s super-power? Well, if you want to build something super lean and blazing fast using Ruby, say an HTTP server API, then Sinatra would be a great choice.

According to Luca Guidi, the creator of Hanami, the overall goal he wanted to achieve with the framework was to give developers a tool that would help them have as much productivity as possible.

Did he deliver on that promise?

Let’s take a look at some of the framework’s stand-out features:

  • Multiple apps within a project – Whereas a Rails app is essentially one large modular app, in Hanami, you can have multiple apps within the main project. Inside the main folder tree, there is a folder called “apps”, in which you can have multiple apps in residence (e.g., a JSON-driven API and a regular web application within one app/project).
  • Fast – At its heart, the framework was built on the idea of minimalism. It tries very hard to avoid the large app structure that is a major feature of a rival like Rails. This focus on minimalism helps greatly in the speed department. Furthermore, it’s said to use 60% less memory compared to other Ruby frameworks.
  • Features over MVC – Whereas Rails is heavily opinionated on how an app should be built, Hanami (especially version 2.0) tries to chart a different path by focusing on building around features. Although explaining this aspect of the framework in detail is beyond the scope of this article, in a nutshell, it means that instead of the framework dictating how you should build an app following some “set rules” (i.e., MVC structure), with Hanami, the developer decides how to build an app based on the desired features.
  • Callable objects – Hanami takes the idea of object-oriented programming to a whole new level. Using a shared mixin-injection system, it is very easy to compose complex objects based on other, much simpler objects.

Of course, this is a very simplified features list. Hanami 2.0 is significantly more than that, and you are highly encouraged to visit the project website to learn more about the framework.

Now that we have a bit more information on what it’s all about, let’s take a look at what you can do with it.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *