Evan You Recommends the High‑Performance H3 Web Framework

H3 is a lightweight, high‑performance HTTP server framework built on Web standards that supports multiple JavaScript runtimes, offers a concise API, composable middleware and plugin systems, and is recommended by Evan You for rapid prototyping, edge computing, and small web services.

Full-Stack Cultivation Path
Full-Stack Cultivation Path
Full-Stack Cultivation Path
Evan You Recommends the High‑Performance H3 Web Framework

What is H3?

H3 is a lightweight HTTP server framework built on Web standards. Its core idea is to provide a concise API and a highly composable toolset while supporting multiple JavaScript runtimes such as Deno, Bun, Node.js, and Workers.

Core Advantages

Lightweight & High Performance : tree‑shakable design keeps the core bundle small, reducing size and improving performance.

Web‑Standard Based : routing and event handling are built on the fetch standard, integrating seamlessly with Web APIs.

Simple API : a few lines of code can create a server and define routes, minimizing boilerplate.

Highly Composable : supports middleware and plugins; middleware can intercept requests, preprocess data, log, etc.

Multi‑Runtime Support : works with Deno, Bun, Node.js, Workers and other JavaScript runtimes.

Quick Start

Installation

npm i h3@beta

Create the first H3 app

import { H3, serve } from "h3";

const app = new H3().get("/", (event) => "Hello, H3!");

serve(app, { port: 3000 });

Core Features

Lifecycle

H3 defines four lifecycle stages: request received, request accepted, request scheduled, and response sent. Developers can hook into each stage with onRequest, onResponse, onError, etc.

Routing

The routing system follows the fetch standard. Routes are defined with app.get, app.post, app.any, and support dynamic parameters.

app
  .get("/hello", () => "GET Hello world!")
  .post("/hello", () => "POST Hello world!")
  .any("/hello", () => "Any other method!");

app.get("/hello/:name", (event) => `Hello, ${event.context.params.name}!`);

Middleware

Middleware can intercept and modify requests. Example logs POST requests to /blog paths.

app.use("/blog/**", (event, next) => {
  console.log("[alert] POST request to /blog");
}, { method: "POST" });

Event Handling

Handlers can be defined with defineHandler and attached to routes.

import { H3, defineHandler } from "h3";

const app = new H3();
const handler = defineHandler(() => "Response");
app.get("/", handler);

Plugins

Plugins extend functionality (e.g., caching, database pools, template engines). Plugins can be registered at instance creation via the plugins option or later with register. Custom plugins are defined with definePlugin.

import { H3 } from "h3";
import { logger } from "./logger.mjs";

// Register at creation
const app = new H3({ plugins: [logger()] });

// Register later
app.register(logger());
import { definePlugin } from "h3";

const logger = definePlugin((h3, _options) => {
  if (h3.config.debug) {
    h3.use((req) => {
      console.log(`[${req.method}] ${req.url}`);
    });
  }
});

Typical Use Cases

Rapid Prototyping : lightweight and fast, suitable for quickly building a server to validate ideas.

Edge Computing : high performance and low resource usage make it appropriate for edge devices and IoT gateways.

Small Web Services : ideal for simple APIs or static file servers without unnecessary overhead.

Resources

Documentation: https://h3.zhcndoc.com/ GitHub:

https://github.com/h3js/h3
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaScriptmiddlewareNode.jsHTTP serverbunDenoH3
Full-Stack Cultivation Path
Written by

Full-Stack Cultivation Path

Focused on sharing practical tech content about TypeScript, Vue 3, front-end architecture, and source code analysis.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.