github honojs/hono v3.5.0

latest releases: v4.6.2, v4.6.1, v4.6.0...
13 months ago

Release Notes

Hono v3.5.0 is now available! Here's what's new.

Secure Headers Middleware

We've added the Secure Headers Middleware. It aids in enhancing your app's security by setting HTTP response headers. It's akin to Helmet for Express.

import { Hono } from 'hono'
import { secureHeaders } from 'hono/secure-headers'

const app = new Hono()

app.use('*', secureHeaders())

app.get('/', (c) => c.text('Hello!'))

// ...

export default app

For an in-depth look, visit the documentation. Thanks @watany-dev for the remarkable contribution!

Introducing "Helpers"

We're unveiling a new concept named "Helpers". While similar to middleware, these are not handlers but handy functions. Prior to this release, the cookie-related functions were a part of the Cookie Middleware. These aren't true middleware. Now, they've been transformed into the "Cookie Helper":

import { getCookie, setCookie } from 'hono/cookie'

const app = new Hono()

app.get('/cookie', (c) => {
  const yummyCookie = getCookie(c, 'yummy_cookie')
  // ...
  setCookie(c, 'delicious_cookie', 'macha')
  // ...
})

However, no worries about breaking changes! The import path hono/cookie remains unchanged. So, usage remains consistent with previous versions.

Zod OpenAPI Middleware

Zod OpenAPI has been rolled out. Zod OpenAPI Hono is an enhanced Hono class supporting OpenAPI. It enables value and type validation using Zod and also facilitates OpenAPI Swagger documentation generation.

Dive deeper with the documentation.

Deprecated Features

The following features are now marked as deprecated:

  • queries in the Validator - Please switch to query.
  • c.runtime() - Transition to the Adapter Helper.
  • app.handleEvent() - Use app.fetch() instead.

These will be removed in version 4.

Additional Features

  • The Validator now has the capability to validate "headers" and "cookies". #1352
  • You can now pass env to getPath(). #1345
  • Body content caching is introduced. #1333
  • hono/context has been exported. #1332

All Updates

New Contributors

Full Changelog: v3.4.3...v3.5.0

Don't miss a new hono release

NewReleases is sending notifications on new releases.