avatar

麦兜的小站

MDO.INK

  • 首页
  • 随笔
  • 知识库
  • 归档
  • 动态
  • 标签
  • 关于
Home Hono - Web framework built on Web Standards
文章

Hono - Web framework built on Web Standards

Posted 2025-01-23 Updated 2025-01- 23
By power 已删除用户
22~28 min read

Hono - means flame🔥 in Japanese - is a small, simple, and ultrafast web framework built on Web Standards. It works on any JavaScript runtime: Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Netlify, AWS Lambda, Lambda@Edge, and Node.js.

Fast, but not only fast.

ts

import { 

Hono

 } from 'hono'
const  

app

 = new  

Hono

()

app

.

get

('/', (

c

) =>  

c

.

text

('Hono!'))
export default  

app

Quick Start ​

Just run this:

npmyarnpnpmbundeno

sh

pnpm create hono@latest

sh

deno init --npm hono@latest

Features ​

  • Ultrafast 🚀 - The router RegExpRouter is really fast. Not using linear loops. Fast.
  • Lightweight 🪶 - The hono/tiny preset is under 14kB. Hono has zero dependencies and uses only the Web Standards.
  • Multi-runtime 🌍 - Works on Cloudflare Workers, Fastly Compute, Deno, Bun, AWS Lambda, or Node.js. The same code runs on all platforms.
  • Batteries Included 🔋 - Hono has built-in middleware, custom middleware, third-party middleware, and helpers. Batteries included.
  • Delightful DX 😃 - Super clean APIs. First-class TypeScript support. Now, we've got "Types".

Use-cases ​

Hono is a simple web application framework similar to Express, without a frontend. But it runs on CDN Edges and allows you to construct larger applications when combined with middleware. Here are some examples of use-cases.

  • Building Web APIs
  • Proxy of backend servers
  • Front of CDN
  • Edge application
  • Base server for a library
  • Full-stack application

Who is using Hono? ​

| Project | Platform | What for? | | --- | --- | --- | | cdnjs | Cloudflare Workers | A free and open-source CDN service. Hono is used for the api server. | | Cloudflare D1 | Cloudflare Workers | Serverless SQL databases. Hono is used for the internal api server. | | BaseAI | Local AI Server | Serverless AI agent pipes with memory. An open-source agentic AI framework for web. API server with Hono. | | Unkey | Cloudflare Workers | An open-source API authentication and authorization. Hono is used for the api server. | | OpenStatus | Bun | An open-source website & API monitoring platform. Hono is used for the api server. | | Deno Benchmarks | Deno | A secure TypeScript runtime built on V8. Hono is used for benchmarking. |

And the following.

  • Drivly - Cloudflare Workers
  • repeat.dev - Cloudflare Workers

Do you want to see more? See Who is using Hono in production?.

Hono in 1 minute ​

A demonstration to create an application for Cloudflare Workers with Hono.

Ultrafast ​

Hono is the fastest, compared to other routers for Cloudflare Workers.

Hono x 402,820 ops/sec ±4.78% (80 runs sampled)
itty-router x 212,598 ops/sec ±3.11% (87 runs sampled)
sunder x 297,036 ops/sec ±4.76% (77 runs sampled)
worktop x 197,345 ops/sec ±2.40% (88 runs sampled)
Fastest is Hono
✨  Done in 28.06s.

See more benchmarks.

Lightweight ​

Hono is so small. With the hono/tiny preset, its size is under 14KB when minified. There are many middleware and adapters, but they are bundled only when used. For context, the size of Express is 572KB.

$ npx wrangler dev --minify ./src/index.ts
 ⛅️ wrangler 2.20.0
--------------------
⬣ Listening at http://0.0.0.0:8787
- http://127.0.0.1:8787
- http://192.168.128.165:8787
Total Upload: 11.47 KiB / gzip: 4.34 KiB

Multiple routers ​

Hono has multiple routers.

RegExpRouter is the fastest router in the JavaScript world. It matches the route using a single large Regex created before dispatch. With SmartRouter, it supports all route patterns.

LinearRouter registers the routes very quickly, so it's suitable for an environment that initializes applications every time. PatternRouter simply adds and matches the pattern, making it small.

See more information about routes.

Web Standards ​

Thanks to the use of the Web Standards, Hono works on a lot of platforms.

  • Cloudflare Workers
  • Cloudflare Pages
  • Fastly Compute
  • Deno
  • Bun
  • Vercel
  • AWS Lambda
  • Lambda@Edge
  • Others

And by using a Node.js adapter, Hono works on Node.js.

See more information about Web Standards.

Middleware & Helpers ​

Hono has many middleware and helpers. These makes "Write Less, do more" a reality.

Out of the box, Hono provides middleware and helpers for:

  • Basic Authentication
  • Bearer Authentication
  • Body Limit
  • Cache
  • Compress
  • Context Storage
  • Cookie
  • CORS
  • ETag
  • html
  • JSX
  • JWT Authentication
  • Logger
  • Pretty JSON
  • Secure Headers
  • SSG
  • Streaming
  • GraphQL Server
  • Firebase Authentication
  • Sentry
  • Others!

For example, adding ETag and request logging only takes a few lines of code with Hono:

ts

import { Hono } from 'hono'
import { etag } from 'hono/etag'
import { logger } from 'hono/logger'
const app = new Hono()
app.use(etag(), logger())

See more information about Middleware.

Developer Experience ​

Hono provides a delightful "Developer Experience".

Easy access to Request/Response thanks to the Context object. Moreover, Hono is written in TypeScript. Hono has "Types".

For example, the path parameters will be literal types.

And, the Validator and Hono Client hc enable the RPC mode. In RPC mode, you can use your favorite validator such as Zod and easily share server-side API specs with the client and build type-safe applications.

前端
License:  CC BY 4.0
Share

Further Reading

Jun 25, 2025

Vue实现顶部导航跟随页面联动效果

需求背景 最近也是应我一位同学的要求,给他的公司制作一个官网,那也就是拾起了一些基础的知识,搜索了一些其它的文章有实现这种效果的,但大多导航都是在侧边,然后点击导航对应的部分内容滑到最上面,跟我这次设...

Jun 20, 2025

Share.js - 一键分享到微博、QQ空间、QQ好友、微信、腾讯微博、豆瓣、Facebook、Twitter、Linkedin、Google+、点点

一键分享到微博、QQ空间、QQ好友、微信、腾讯微博、豆瓣、Facebook、Twitter、Linkedin、Google+、点点等社交网站,使用字体图标。 有两种安装方式: 使用npm npmi...

Jun 19, 2025

node express实现热更新

在使用node进行开发的时候,每次修改文件,都需要重启express服务很麻烦 我们可以使用nodemon这个库,修改文件后可以自动重启express服务。 安装: npminstall--save-...

OLDER

运行您的第一个 Deno 程序

NEWER

用PHP调用Python程序

Recently Updated

  • 如何实现接口幂等性
  • 10个npm工具包
  • How to set up PHP7.4 on MacOS.
  • Automa:一键自动化,网页数据采集与工作流程优化专家Automa:解锁自动化
  • Mac 下用 brew 搭建 LNMP

Trending Tags

thinkphp clippings

Contents

©2025 麦兜的小站. Some rights reserved.

Using the Halo theme Chirpy