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
Framework | Results |
Hono | 616.464 ops/sec (±4.76%) |
Itty-router | 203.074 ops/sec (±3.66%) |
sunder | 314.306 ops/sec (±2.28%) |
worktop | 194.111 ops/sec (±2.78%) |
source: Hono official website
On Deno
Source Code: benchmarks/deno
Framework | Version | Results |
Hono | 2.2.0 | 176976 req/sec |
Fast | 4.0.0-beta.1 | 148011 req/sec |
Faster | 5.7 | 36332 req/sec |
Oak | 10.5.1 | 34641 req/sec |
Opine | 2.2.0 | 21102 req/sec |
source: Hono official website
On Bun
Source Code: SaltyAom/bun-http-framework-benchmark
Framework | Get (/) | Params, query & header | Post JSON |
baojs | 89,815.61 req/sec | 78,893.78 req/sec | 73,613.71 req/sec |
bun-bakery | 112,590.01 req/sec | 79,890.18 req/sec | 69,406.26 req/sec |
bun | 163,705.35 req/sec | 129,364.36 req/sec | 89,723.65 req/sec |
colston | 7,716.77 req/sec | 103,185.97 req/sec | 11,604.82 req/sec |
express | 24,538.77 req/sec | 23,865.71 req/sec | 6,491.6 req/sec |
hono | 186,835.8 req/sec | 138,642.78 req/sec | 93,240.68 req/sec |
hyperbun | 97,856.71 req/sec | 74,648.01 req/sec | 68,810.79 req/sec |
kingworld | 158,395.62 req/sec | 129,790.04 req/sec | 89,371.59 req/sec |
nbit | 87,300.5 req/sec | 73,024.87 req/sec | 68,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