Today we are excited to announce Hanami 2.3! With this release, we unlock Rack 3, introduce resource routes, and deliver dozens of quality-of-life improvements that make building with Hanami smoother than ever.
Built for Rack 3
We are excited to bring Rack 3 support to Hanami! We now support both versions 2 and 3, so you can use whichever version of Rack suits your situation. We encourage you to upgrade Rack when you can, and we’re happy that Hanami can help you on this path.
When you upgrade to Rack 3, check out the Rack 3 upgrade guide. Hanami already handles the essential changes for you, but you may need to update your app code if you’re working with Rack request/response details.
Streamlined from route to response
More than just Rack, we’ve refined all aspects of our routing and request handling layer. The biggest change is the return of resource-based routing.
To set up RESTful routes, you’d previously add the following lines:
# Previously...
get "/books", to: "books.index", as: :books
get "/books/:id", to: "books.show", as: :book
get "/books/new", to: "books.new", as: :new_book
post "/books", to: "books.create"
get "/books/:id/edit", to: "books.edit", as: :edit_book
patch "/books/:id", to: "books.update"
delete "/books/:id", to: "books.destroy"
Now, all you need is one:
# Now! 🥰
resources :books
Resource routing is integrated with every aspect of routing. Resources can be customized, nested, and combined with scopes and ordinary routes. Learn more here.
The improvements don’t stop there! With this release:
- Route scopes can be given custom name prefixes.
- Routes can be named with a prefix that precedes scope prefixes.
- Router runtime performance is considerably improved for large numbers of routes.
- Multipart form and JSON request bodies are parsed by default.
- Action format and media type config is clearer and more flexible.
- You can access your subdomains via
Request#subdomains, and configure your TLD length. - When you add
'nonce'to your content security policy, nonces are automatically added to script and stylesheet tags. - CSRF tokens are loaded from the
X-CSRF-Tokenheader in addition to request params.
DX in the details
We’ve also improved many more of your day-to-day interactions with Hanami:
hanami newnow initializes a Git repository for new apps. You can also provide--skip-viewto skip the view layer, as well as--gem-source, so you can use gem.coop from the get-go.- New apps get a helpful
bin/setupscript, as well as an improved README with a handy list of first steps. - New apps also receive a
bin/hanamibinstub, so you can invokebin/hanamiwithout requiring abundle exec. - Run
hanami db rollbackto easily rollback a database migration. - Add your own methods to
hanami consolevia your own modules: addconfig.console.include MyModulein your app class. - Prefer Pry to IRB? Make it the default with
config.console.engine = :pry. - The console now prints a one-time warning when you access the
keysfor an un-booted app or slice. You can also chose to boot your app preemptively withhanami console --boot. - The default
Rakefilewill automatically load custom tasks fromlib/tasks/. - View context classes are generated by default, so you can more easily see where to put custom view logic.
- Run
hanami generatecommand within a slice directory and the generated file will target that slice automatically.
We’ve made dozens more small improvements and fixes. Check out the changelogs to learn more.
Try Hanami 2.3
There’s never been a better time to try Hanami. For this release we’ve made our getting started guide more concise and easier to follow. Now you can get up and running faster than ever!
Why don’t you give it a try? Your first Hanami app is just a few commands away:
$ gem install hanami
$ hanami new my_app
$ cd my_app
$ bin/hanami dev
$ open http://localhost:2300
We’d love to hear how you go! Come join our Discord or forum and share your experience with our lovely community.
And if you’re a certified legend already rocking a Hanami app, make sure to check out the upgrade notes for 2.3.
Thank you to our contributors!
Hanami 2.3 is a significant release: it comes courtesy of our biggest contributors group yet. Thank you to all these wonderful humans!
- Aaron Allen
- Adam Lassek
- Alexander Gräfe
- Alexander Zagaynov
- Andrea Fomera
- Brandon Weaver
- Damian C. Rossney
- David Celis
- Hana Rimawi
- inouire
- Jared White
- Jojo Hall
- Krzysztof Piotrowski
- Kyle Plump
- Mathew Button
- Max Mitchell
- Mina Slater
- Paweł Świątkowski
- Petrik de Heus
- Philip Arndt
- Rob Yurkowski
- Ryan Bigg
- Sean Collins
- Simon Thiboutôt
- stephannv
- Sven Schwyn
- Tim Morgan
- Tim Riley
- William Tio
- Wout
- wuarmin
- y-yagi
There’s always room for more. Our community is inclusive and welcoming, and we’d love to have you join us.
Thank you to our patrons! 🌸
This is also our first major release since launching our sponsorship program. I’d like to extend my deepest thanks to our founding patrons: Sidekiq, Brandon Weaver, Honeybadger, FastRuby.io and AppSignal. Without you, this release wouldn’t have been possible.
Thank you also to the individuals supporting Hanami through our GitHub Sponsors. There are now 21 of you!
We’d love for you to become a patron too. Learn more here.