Hono, "Ultrafast" Web Framework for the Edge

Hono is a lightweight web framework that executes on-edge environments such as Cloudflare Workers and Bun, Deno, and Node.js. It comes with baked-in support for TypeScript, relies on no external dependency, and employs a "smart routing" technique that promises "ultrafast" performance on all platforms.

What is Hono

Hono is advertised as an ultrafast web framework that can be deployed on the edge and all major JavaScript environments. Hono developers say on their official page that:

Hono - [炎] means flame🔥 in Japanese - is a small, simple, and ultrafast web framework for Cloudflare Workers, Deno, Bun, and others.

Hono Features

Hono gives developers 5 features that would help make web development simple and effective while ensuring high-performance standards:

  • Hono is ultrafast thanks to its smart routing technique which automatically chooses the best routing algorithm upon request.

  • Hono has zero dependencies as it uses the Web Standard API for networking and HTTP protocol communications.

  • Hono has built-in middleware for repetitive tasks such as authentication, CORS, cache, compression, GraphQL server, and many more.

  • Hono has first-class TypeScript support for an improved developer experience.

  • Hono is executable on multiple JavaScript platforms with the same codebase.

Development in Hono

Hono's API seems quite similar to the widely known Express.js. However, route callbacks receive a Context object that performs actions both on request and response data.

To run Hono on Bun.js:

 bun add hono

Then create index.ts with the following code:

import { Hono } from 'hono'

const app = new Hono();

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

and run:

bun ./index.ts

Running Hono on Node.js requires an extra dependency, @honojs/node-server which serves as an adapter to serve the application.

To run Hono on Node.js:

npm i --save hono @honojs/node-server typescript
# or
yarn add hono @honojs/node-server typescript

Then create index.ts with the following code:

import { serve } from '@honojs/node-server'
import { Hono } from 'hono'

const app = new Hono();

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

serve(app)

and run it either by compiling index.ts :

npx tsc .
node ./index.js

or using ts-node:

## install ts-node
npm i ts-node --save-dev
# or
yarn add -D ts-node

## run the server
ts-node ./index.ts

Hono Benchmarks

According to the official benchmarks performed by Hono creators ( Public Source Code ) shows that Hono outperforms the majority of widely-used edge-compatible web frameworks, such as Deno's fast, faster and opine.

On Cloudflare Workers

Source Code: benchmarks/handle-event

FrameworkResults
Hono616.464 ops/sec (±4.76%)
Itty-router203.074 ops/sec (±3.66%)
sunder314.306 ops/sec (±2.28%)
worktop194.111 ops/sec (±2.78%)

source: Hono official website

On Deno

Source Code: benchmarks/deno

FrameworkVersionResults
Hono2.2.0176976 req/sec
Fast4.0.0-beta.1148011 req/sec
Faster5.736332 req/sec
Oak10.5.134641 req/sec
Opine2.2.021102 req/sec

source: Hono official website

On Bun

Source Code: SaltyAom/bun-http-framework-benchmark

FrameworkGet (/)Params, query & headerPost JSON
baojs89,815.61 req/sec78,893.78 req/sec73,613.71 req/sec
bun-bakery112,590.01 req/sec79,890.18 req/sec69,406.26 req/sec
bun163,705.35 req/sec129,364.36 req/sec89,723.65 req/sec
colston7,716.77 req/sec103,185.97 req/sec11,604.82 req/sec
express24,538.77 req/sec23,865.71 req/sec6,491.6 req/sec
hono186,835.8 req/sec138,642.78 req/sec93,240.68 req/sec
hyperbun97,856.71 req/sec74,648.01 req/sec68,810.79 req/sec
kingworld158,395.62 req/sec129,790.04 req/sec89,371.59 req/sec
nbit87,300.5 req/sec73,024.87 req/sec68,067.32 req/sec

source: SaltyAom's benchmark repository

Conclusion

Hono is a promising web framework for the edge that provides decent performance, without sacrificing developer experience. It has an API that is similar to the widely-adopted express.js with middlewares that cover most of the typical use cases like authentication and validation.

Whether Hono will be the de-facto framework for edge web servers is debatable. However, given its performance and ease of use, it is possible that Hono will stand firm and have a good share of deployments in edge environments, especially for Cloudflare Workers.

For more articles, tutorials and news about open-source projects, visit my blog at devdog.co

Did you find this article valuable?

Support Houssem Eddine Zerrad by becoming a sponsor. Any amount is appreciated!