@depup/h3 2.0.1-rc.17-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/bin/h3.mjs +35 -0
  4. package/changes.json +5 -0
  5. package/dist/THIRD-PARTY-LICENSES.md +70 -0
  6. package/dist/_entries/bun.d.mts +8 -0
  7. package/dist/_entries/bun.mjs +11 -0
  8. package/dist/_entries/cloudflare.d.mts +8 -0
  9. package/dist/_entries/cloudflare.mjs +11 -0
  10. package/dist/_entries/deno.d.mts +8 -0
  11. package/dist/_entries/deno.mjs +11 -0
  12. package/dist/_entries/generic.d.mts +8 -0
  13. package/dist/_entries/generic.mjs +11 -0
  14. package/dist/_entries/node.d.mts +12 -0
  15. package/dist/_entries/node.mjs +14 -0
  16. package/dist/_entries/service-worker.d.mts +8 -0
  17. package/dist/_entries/service-worker.mjs +11 -0
  18. package/dist/h3-C304D6TZ.d.mts +1275 -0
  19. package/dist/h3-CGHxXEqb.mjs +2605 -0
  20. package/dist/h3-DagAgogP.mjs +4 -0
  21. package/dist/h3-QfzdiyNf.d.mts +836 -0
  22. package/dist/tracing.d.mts +26 -0
  23. package/dist/tracing.mjs +76 -0
  24. package/package.json +128 -0
  25. package/skills/h3/SKILL.md +10 -0
  26. package/skills/h3/docs/TOC.md +35 -0
  27. package/skills/h3/docs/_navigation.json +311 -0
  28. package/skills/h3/docs/examples/handle-cookie.md +67 -0
  29. package/skills/h3/docs/examples/handle-session.md +130 -0
  30. package/skills/h3/docs/examples/index.md +16 -0
  31. package/skills/h3/docs/examples/serve-static-assets.md +66 -0
  32. package/skills/h3/docs/examples/stream-response.md +76 -0
  33. package/skills/h3/docs/examples/validate-data.md +193 -0
  34. package/skills/h3/docs/guide/advanced/nightly.md +13 -0
  35. package/skills/h3/docs/guide/advanced/plugins.md +50 -0
  36. package/skills/h3/docs/guide/advanced/websocket.md +124 -0
  37. package/skills/h3/docs/guide/api/h3.md +145 -0
  38. package/skills/h3/docs/guide/api/h3event.md +113 -0
  39. package/skills/h3/docs/guide/basics/error.md +117 -0
  40. package/skills/h3/docs/guide/basics/handler.md +165 -0
  41. package/skills/h3/docs/guide/basics/lifecycle.md +68 -0
  42. package/skills/h3/docs/guide/basics/middleware.md +97 -0
  43. package/skills/h3/docs/guide/basics/nested-apps.md +57 -0
  44. package/skills/h3/docs/guide/basics/response.md +162 -0
  45. package/skills/h3/docs/guide/basics/routing.md +92 -0
  46. package/skills/h3/docs/guide/index.md +117 -0
  47. package/skills/h3/docs/migration/index.md +200 -0
  48. package/skills/h3/docs/utils/community.md +42 -0
  49. package/skills/h3/docs/utils/cookie.md +33 -0
  50. package/skills/h3/docs/utils/index.md +46 -0
  51. package/skills/h3/docs/utils/mcp.md +71 -0
  52. package/skills/h3/docs/utils/more.md +78 -0
  53. package/skills/h3/docs/utils/proxy.md +31 -0
  54. package/skills/h3/docs/utils/request.md +355 -0
  55. package/skills/h3/docs/utils/response.md +144 -0
  56. package/skills/h3/docs/utils/security.md +109 -0
@@ -0,0 +1,57 @@
1
+ # Nested Apps
2
+
3
+ > H3 has a native `mount` method for adding nested sub-apps to the main instance.
4
+
5
+ Typically, H3 projects consist of several [Event Handlers](/guide/basics/handler) defined in one or multiple files (or even [lazy loaded](/guide/basics/handler#lazy-handlers) for faster startup times).
6
+
7
+ It is sometimes more convenient to combine multiple `H3` instances or even use another HTTP framework used by a different team and mount it to the main app instance. H3 provides a native [`.mount`](/guide/api/h3#h3mount) method to facilitate this.
8
+
9
+ ## Nested H3 Apps
10
+
11
+ H3 natively allows mounting sub-apps. When mounted, sub-app routes and middleware are **merged** with the base url prefix into the main app instance.
12
+
13
+ ```js
14
+ import { H3, serve } from "h3";
15
+
16
+ const nestedApp = new H3()
17
+ .use((event) => {
18
+ event.res.headers.set("x-api", "1");
19
+ })
20
+ .get("/**:slug", (event) => ({
21
+ pathname: event.url.pathname,
22
+ slug: event.context.params?.slug,
23
+ }));
24
+
25
+ const app = new H3().mount("/api", nestedApp);
26
+ ```
27
+
28
+ In the example above, when fetching the `/api/test` URL, `pathname` will be `/api/test` (the real path), and `slug` will be `/test` (wildcard param).
29
+
30
+ > [!NOTE]
31
+ > Global config and hooks won't be inherited from the nested app. Consider always setting them from the main app.
32
+
33
+ ## Nested Web Standard Apps
34
+
35
+ Mount a `.fetch` compatible server instance like [Hono](https://hono.dev/) or [Elysia](https://elysiajs.com/) under the base URL.
36
+
37
+ > [!NOTE]
38
+ > Base prefix will be removed from `request.url` passed to the mounted app.
39
+
40
+ ```js
41
+ import { H3 } from "h3";
42
+ import { Hono } from "hono";
43
+ import { Elysia } from "elysia";
44
+
45
+ const app = new H3()
46
+ .mount(
47
+ "/elysia",
48
+ new Elysia().get("/test", () => "Hello Elysia!"),
49
+ )
50
+ .mount(
51
+ "/hono",
52
+ new Hono().get("/test", (c) => c.text("Hello Hono!")),
53
+ );
54
+ ```
55
+
56
+ > [!TIP]
57
+ > Similarly, you can mount an H3 app in [Hono](https://hono.dev/docs/api/hono#mount) or [Elysia](https://elysiajs.com/patterns/mount#mount-1).
@@ -0,0 +1,162 @@
1
+ # Sending Response
2
+
3
+ > H3 automatically converts any returned value into a web response.
4
+
5
+ Values returned from [Event Handlers](/guide/basics/handler) are automatically converted to a web [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) by H3.
6
+
7
+ **Example:** Simple event handler function.
8
+
9
+ ```js
10
+ const handler = defineHandler((event) => ({ hello: "world" }));
11
+ ```
12
+
13
+ H3 smartly converts handler into:
14
+
15
+ ```js
16
+ const handler = (event) =>
17
+ new Response(JSON.stringify({ hello: "world" }), {
18
+ headers: {
19
+ "content-type": "application/json;charset=UTF-8",
20
+ },
21
+ });
22
+ ```
23
+
24
+ > [!TIP]
25
+ > 🚀 H3 uses srvx `FastResponse` internally to optimize performances in Node.js runtime.
26
+
27
+ If the returned value from event handler is a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or from an [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function), H3 will wait for it to resolve before sending the response.
28
+
29
+ If an error is thrown, H3 automatically handles it with error handler.
30
+
31
+ <read-more></read-more>
32
+
33
+ ## Preparing Response
34
+
35
+ Before returning a response in main handler, you can prepare response headers and status using [`event.res`](/guide/api/h3event#eventres).
36
+
37
+ ```js
38
+ defineHandler((event) => {
39
+ event.res.status = 200;
40
+ event.res.statusText = "OK";
41
+ event.res.headers.set("Content-Type", "text/html");
42
+ return "<h1>Hello, World</h1>";
43
+ });
44
+ ```
45
+
46
+ > [!NOTE]
47
+ > If a full [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response) value is returned, prepared status is discarded and headers will be merged/overriden. For performance reasons, it is best to only set headers only from final Response in this case.
48
+
49
+ > [!NOTE]
50
+ > If an Error happens, prepared status and headers will be discarded. The recommended way to include headers in error responses is via `new HTTPError({ headers })`. As a last resort for headers that need to be set implicitly before the error is known (e.g., CORS), you can use `event.res.errHeaders` — these will be merged into error responses automatically.
51
+
52
+ ## Response Types
53
+
54
+ H3 smartly converts JavaScript values into web [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response).
55
+
56
+ ### JSON Serializable Value
57
+
58
+ Returning a [JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) serializable value (**object**, **array**, **number** or **boolean**), it will be stringified using [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) and sent with default `application/json` content-type.
59
+
60
+ **Example:**
61
+
62
+ ```ts
63
+ app.get("/", (event) => ({ hello: "world" }));
64
+ ```
65
+
66
+ > [!TIP]
67
+ > Returned objects with `.toJSON()` property can customize serialization behavior. Check [MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) for more info.
68
+
69
+ ### String
70
+
71
+ Returning a string value, sends it as plain text body.
72
+
73
+ > [!NOTE]
74
+ > If not setting `content-type` header, it can default to `text/plain;charset=UTF-8`.
75
+
76
+ **Example:** Send HTML response.
77
+
78
+ ```ts
79
+ app.get("/", (event) => {
80
+ event.res.headers.set("Content-Type", "text/html;charset=UTF-8");
81
+ return "<h1>hello world</h1>";
82
+ });
83
+ ```
84
+
85
+ You can also use `html` utility as shortcut.
86
+
87
+ ```js
88
+ import { html } from "h3";
89
+
90
+ app.get("/", () => html("<h1>hello world</h1>"));
91
+ ```
92
+
93
+ ### `Response`
94
+
95
+ Returning a web [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response), sends-it as final reponse.
96
+
97
+ **Example:**
98
+
99
+ ```ts
100
+ app.get("/", (event) => new Response("Hello, world!", { headers: { "x-powered-by": "H3" } }));
101
+ ```
102
+
103
+ > [!IMPORTANT]
104
+ > When sending a `Response`, any [prepared headers](#preparing-response) that set before, will be merged as default headers. `event.res.{status,statusText}` will be ignored. For performance reasons, it is best to only set headers only from final `Response`.
105
+
106
+ ### `ReadableStream` or `Readable`
107
+
108
+ Returning a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) or Node.js [`Readable`](https://nodejs.org/api/stream.html#readable-streams) sends it as stream.
109
+
110
+ ### `ArrayBuffer` or `Uint8Array` or `Buffer`
111
+
112
+ Send binary [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) or node [Buffer](https://nodejs.org/api/buffer.html#buffer).
113
+
114
+ `content-length` header will be automatically set.
115
+
116
+ ### `Blob`
117
+
118
+ Send a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) as stream.
119
+
120
+ `Content-type` and `Content-Length` headers will be automatically set.
121
+
122
+ ### `File`
123
+
124
+ Send a [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) as stream.
125
+
126
+ `Content-type`, `Content-Length` and `Content-Disposition` headers will be automatically set.
127
+
128
+ ## Special Types
129
+
130
+ Some less commonly possible values for response types.
131
+
132
+ ### `null` or `undefined`
133
+
134
+ Sends a response with empty body.
135
+
136
+ > [!TIP]
137
+ > If there is no `return` statement in event handler, it is same as `return undefined`.
138
+
139
+ ### `Error`
140
+
141
+ Retuning an [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) instance will send it.
142
+
143
+ > [!IMPORTANT]
144
+ > It is better to `throw` errors instead of returning them. This allows proper propagation from any nested utility.
145
+
146
+ <read-more></read-more>
147
+
148
+ ### `BigInt`
149
+
150
+ Value will be sent as stringified version of BigInt number.
151
+
152
+ > [!NOTE]
153
+ > Returning a JSON object, does not allows BigInt serialization. You need to implement `.toJSON`. Check [MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) for more info.
154
+
155
+ ### `Symbol` or `Function`
156
+
157
+ **Returning Symbol or Function has undetermined behavior.** Currently, H3 sends a string-like representation of unknown Symbols and Functions but this behavior might be changed to throw an error in the future versions.
158
+
159
+ There are some internal known Symbols H3 internally uses:
160
+
161
+ - `Symbol.for("h3.notFound")`: Indicate no route is found to throw a 404 error.
162
+ - `Symbol.for("h3.handled")`: Indicate request is somehow handled and H3 should not continue (Node.js specific).
@@ -0,0 +1,92 @@
1
+ # Routing
2
+
3
+ > Each request is matched to one (most specific) route handler.
4
+
5
+ ## Adding Routes
6
+
7
+ You can register route [handlers](/guide/basics/handler) to [H3 instance](/guide/api/h3) using [`H3.on`](/guide/api/h3#h3on), [`H3.[method]`](/guide/api/h3#h3method), or [`H3.all`](/guide/api/h3#h3all).
8
+
9
+ > [!TIP]
10
+ > Router is powered by [🌳 Rou3](https://github.com/h3js/rou3), an ultra-fast and tiny route matcher engine.
11
+
12
+ **Example:** Register a route to match requests to the `/hello` endpoint with HTTP **GET** method.
13
+
14
+ - Using [`H3.[method]`](/guide/api/h3#h3method)
15
+
16
+ ```js
17
+ app.get("/hello", () => "Hello world!");
18
+ ```
19
+
20
+ - Using [`H3.on`](/guide/api/h3#h3on)
21
+
22
+ ```js
23
+ app.on("GET", "/hello", () => "Hello world!");
24
+ ```
25
+
26
+
27
+ You can register multiple event handlers for the same route with different methods:
28
+
29
+ ```js
30
+ app
31
+ .get("/hello", () => "GET Hello world!")
32
+ .post("/hello", () => "POST Hello world!")
33
+ .all("/hello", () => "Any other method!");
34
+ ```
35
+
36
+ You can also use [`H3.all`](/guide/api/h3#h3all) method to register a route accepting any HTTP method:
37
+
38
+ ```js
39
+ app.all("/hello", (event) => `This is a ${event.req.method} request!`);
40
+ ```
41
+
42
+ ## Dynamic Routes
43
+
44
+ You can define dynamic route parameters using `:` prefix:
45
+
46
+ ```js
47
+ // [GET] /hello/Bob => "Hello, Bob!"
48
+ app.get("/hello/:name", (event) => {
49
+ return `Hello, ${event.context.params.name}!`;
50
+ });
51
+ ```
52
+
53
+ Instead of named parameters, you can use `*` for unnamed **optional** parameters:
54
+
55
+ ```js
56
+ app.get("/hello/*", (event) => `Hello!`);
57
+ ```
58
+
59
+ ## Wildcard Routes
60
+
61
+ Adding `/hello/:name` route will match `/hello/world` or `/hello/123`. But it will not match `/hello/foo/bar`.
62
+ When you need to match multiple levels of sub routes, you can use `**` prefix:
63
+
64
+ ```js
65
+ app.get("/hello/**", (event) => `Hello ${event.context.params._}!`);
66
+ ```
67
+
68
+ This will match `/hello`, `/hello/world`, `/hello/123`, `/hello/world/123`, etc.
69
+
70
+ > [!NOTE]
71
+ > Param `_` will store the full wildcard content as a single string.
72
+
73
+ ## Route Meta
74
+
75
+ You can define optional route meta when registering them, accessible from any middleware.
76
+
77
+ ```js
78
+ import { H3 } from "h3";
79
+
80
+ const app = new H3();
81
+
82
+ app.use((event) => {
83
+ console.log(event.context.matchedRoute?.meta); // { auth: true }
84
+ });
85
+
86
+ app.get("/", (event) => "Hi!", { meta: { auth: true } });
87
+ ```
88
+
89
+ <read-more>
90
+
91
+ It is also possible to add route meta when defining them using `defineHandler` object syntax.
92
+ </read-more>
@@ -0,0 +1,117 @@
1
+ # Getting Started
2
+
3
+ > Get started with H3.
4
+
5
+ > [!IMPORTANT]
6
+ > You are currently reading H3 v2 docs. See [v1.h3.dev](https://v1.h3.dev/) for legacy docs.
7
+
8
+ ## Overview
9
+
10
+ ⚡ H3 (short for H(TTP), pronounced as /eɪtʃθriː/, like h-3) is a lightweight, fast, and composable server framework for modern JavaScript runtimes. It is based on web standard primitives such as [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request), [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response), [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL), and [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers). You can integrate H3 with any compatible runtime or [mount](/guide/api/h3#h3mount) other web-compatible handlers to H3 with almost no added latency.
11
+
12
+ H3 is designed to be extendable and composable. Instead of providing one big core, you start with a lightweight [H3 instance](/guide/api/h3) and then import built-in, tree-shakable [utilities](/utils) or bring your own for more functionality.
13
+ Composable utilities has several advantages:
14
+
15
+ - The server only includes used code and runs them exactly where is needed.
16
+ - Application size can scale better. Usage of utilities is explicit and clean, with less global impact.
17
+ - H3 is minimally opinionated and won't limit your choices.
18
+ All utilities, share an [H3Event](/guide/api/h3event) context.
19
+
20
+ <read-more></read-more>
21
+
22
+ ## Quick Start
23
+
24
+ > [!TIP]
25
+ > You try H3 online [on ⚡️ Stackblitz ](https://stackblitz.com/github/h3js/h3/tree/main/playground?file=server.mjs).
26
+
27
+ Install `h3` as a dependency:
28
+
29
+ <pm-install></pm-install>
30
+
31
+ Create a new file for server entry:
32
+
33
+ ```ts [server.mjs]
34
+ import { H3, serve } from "h3";
35
+
36
+ const app = new H3().get("/", (event) => "⚡️ Tadaa!");
37
+
38
+ serve(app, { port: 3000 });
39
+ ```
40
+
41
+ Then, run the server using your favorite runtime:
42
+
43
+ <code-group>
44
+
45
+ ```bash [node]
46
+ node --watch ./server.mjs
47
+ ```
48
+
49
+ ```bash [deno]
50
+ deno run -A --watch ./server.mjs
51
+ ```
52
+
53
+ ```bash [bun]
54
+ bun run --watch server.mjs
55
+ ```
56
+ </code-group>
57
+
58
+ And tadaa! We have a web server running locally.
59
+
60
+ ### What Happened?
61
+
62
+ Okay, let's now break down our hello world example.
63
+
64
+ We first created an [H3](/guide/api/h3) app instance using `new H3()`:
65
+
66
+ ```ts
67
+ const app = new H3();
68
+ ```
69
+
70
+ [H3](/guide/api/h3) is a tiny class capable of [matching routes](/guide/basics/routing), [generating responses](/guide/basics/response) and calling [middleware](/guide/basics/middleware) and [global hooks](/guide/api/h3#global-hooks).
71
+
72
+ Then we add a route for handling HTTP GET requests to `/` path.
73
+
74
+ ```ts
75
+ app.get("/", (event) => {
76
+ return { message: "⚡️ Tadaa!" };
77
+ });
78
+ ```
79
+
80
+ <read-more></read-more>
81
+
82
+ We simply returned an object. H3 automatically [converts](/guide/basics/response#response-types) values into web responses.
83
+
84
+ <read-more></read-more>
85
+
86
+ Finally, we use `serve` method to start the server listener. Using `serve` method you can easily start an H3 server in various runtimes.
87
+
88
+ ```js
89
+ serve(app, { port: 3000 });
90
+ ```
91
+
92
+ > [!TIP]
93
+ > The `serve` method is powered by [💥 srvx](https://srvx.h3.dev/), a runtime-agnostic universal server listener based on web standards that works seamlessly with [Deno](https://deno.com/), [Node.js](https://nodejs.org/) and [Bun](https://bun.sh/).
94
+
95
+ We also have [`app.fetch`](/guide/api/h3#h3fetch) which can be directly used to run H3 apps in any web-compatible runtime or even directly called for testing purposes.
96
+
97
+ <read-more></read-more>
98
+
99
+ ```js
100
+ import { H3, serve } from "h3";
101
+
102
+ const app = new H3().get("/", () => "⚡️ Tadaa!");
103
+
104
+ // Test without listening
105
+ const response = await app.request("/");
106
+ console.log(await response.text());
107
+ ```
108
+
109
+ You can directly import `h3` library from CDN alternatively. This method can be used for Bun, Deno and other runtimes such as Cloudflare Workers.
110
+
111
+ ```js
112
+ import { H3 } from "https://esm.sh/h3";
113
+
114
+ const app = new H3().get("/", () => "⚡️ Tadaa!");
115
+
116
+ export const fetch = app.fetch;
117
+ ```
@@ -0,0 +1,200 @@
1
+ # Migration guide for v1 to v2
2
+
3
+ H3 version 2 includes some behavior and API changes that you need to consider applying when migrating.
4
+
5
+ > [!NOTE]
6
+ > Currently H3 v2 in beta stage. You can try with [nightly channel](/guide/advanced/nightly).
7
+
8
+ > [!NOTE]
9
+ > This is an undergoing migration guide and might be updated.
10
+
11
+ > [!TIP]
12
+ > H3 has a brand new documentation rewrite. Head to the new [Guide](/guide) section to learn more!
13
+
14
+ ## Latest Node.js and ESM-only
15
+
16
+ > [!TIP]
17
+ > H3 v2 requires Node.js >= 20.11 (latest LTS recommended) .
18
+
19
+ If your application is currently using CommonJS modules (`require` and `module.exports`), You can still use `require("h3")` thanks to `require(esm)` supported in latest Node.js versions.
20
+
21
+ You can alternatively use other compatible runtimes [Bun](https://bun.sh/) or [Deno](https://deno.com/).
22
+
23
+ ## Web Standards
24
+
25
+ > [!TIP]
26
+ > H3 v2 is rewritten based on web standard primitives ([`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL), [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers), [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request), and [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)).
27
+
28
+ When using Node.js, H3 uses a compatibility layer ([💥 srvx](https://srvx.h3.dev/guide/node)) and in other runtimes uses native web compatibility APIs.
29
+
30
+ Access to the native `event.node.{req,res}` is only available when running server in Node.js runtime.
31
+
32
+ `event.web` is renamed to `event.req` (instance of web [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request)).
33
+
34
+ ## Response Handling
35
+
36
+ > [!TIP]
37
+ > You should always explicitly **return** the response body or **throw** an error.
38
+
39
+ If you were previously using methods below, you can replace them with `return` statements returning a text, JSON, stream, or web `Response` (h3 smartly detects and handles each):
40
+
41
+ - `send(event, value)`: Migrate to `return <value>`.
42
+ - `sendError(event, <error>)`: Migrate to `throw createError(<error>)`.
43
+ - `sendStream(event, <stream>)`: Migrate to `return <stream>`.
44
+ - `sendWebResponse(event, <response>)`: Migrate to `return <response>`.
45
+ Other send utils that are renamed and need explicit `return`:
46
+
47
+ - `sendNoContent(event)` / `return null`: Migrate to `return noContent()`.
48
+ - `sendIterable(event, <value>)`: Migrate to `return iterable(<value>)`.
49
+ - `sendProxy(event, target)`: Migrate to `return proxy(event, target)`.
50
+ - `handleCors(event)`: Check return value and early `return` if handled(not `false`).
51
+ - `serveStatic(event, content)`: Make sure to add `return` before.
52
+ - `sendRedirect(event, location, code)`: Migrate to `return redirect(location, code)`.
53
+ <read-more></read-more>
54
+
55
+ ## H3 and Router
56
+
57
+ > [!TIP]
58
+ > Router function is now integrated into the H3 core.
59
+ > Instead of `createApp()` and `createRouter()` you can use [`new H3()`](/guide/api/h3).
60
+
61
+ Any handler can return a response. If middleware don't return a response, next handlers will be tried and finally make a 404 if neither responses. Router handlers can return or not return any response, in this case, H3 will send a simple 200 with empty content.
62
+
63
+ <read-more></read-more>
64
+
65
+ H3 migrated to a brand new route-matching engine ([🌳 rou3](https://rou3.h3.dev/)). You might experience slight (but more intuitive) behavior changes for matching patterns.
66
+
67
+ **Other changes from v1:**
68
+
69
+ - Middleware added with `app.use("/path", handler)` only matches `/path` (not `/path/foo/bar`). For matching all subpaths like before, it should be updated to `app.use("/path/**", handler)`.
70
+ - The `event.path` received in each handler will have a full path without omitting the prefixes. use `withBase(base, handler)` utility to make prefixed app. (example: `withBase("/api", app.handler)`).
71
+ - **`router.add(path, method: Method | Method[]` signature is changed to `router.add(method: Method, path)`**
72
+ - `router.use(path, handler)` is deprecated. Use `router.all(path, handler)` instead.
73
+ - `app.use(() => handler, { lazy: true })` is no supported anymore. Instead you can use `app.use(defineLazyEventHandler(() => handler), { lazy: true })`.
74
+ - `app.use(["/path1", "/path2"], ...)` and `app.use("/path", [handler1, handler2])` are not supported anymore. Instead, use multiple `app.use()` calls.
75
+ - `app.resolve(path)` removed.
76
+ <read-more></read-more>
77
+
78
+ <read-more></read-more>
79
+
80
+ ## Request Body
81
+
82
+ > [!TIP]
83
+ > Most of request body utilities can now be replaced with native `event.req.*` methods which is based on web [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Response) interface.
84
+
85
+ `readBody(event)` utility will use [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) or [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) for parsing requests with `application/x-www-form-urlencoded` content-type.
86
+
87
+ - For text: Use [event.req.text()](https://developer.mozilla.org/en-US/docs/Web/API/Request/text).
88
+ - For json: Use [event.req.json()](https://developer.mozilla.org/en-US/docs/Web/API/Request/json).
89
+ - For formData: Use [event.req.formData()](https://developer.mozilla.org/en-US/docs/Web/API/Request/formData).
90
+ - For stream: Use [event.req.body](https://developer.mozilla.org/en-US/docs/Web/API/Request/body).
91
+ **Behavior changes:**
92
+
93
+ - Body utils won't throw an error if the incoming request has no body (or is a `GET` method for example) but instead, return empty values.
94
+ - Native `request.json` and `readBody` does not use [unjs/destr](https://destr.unjs.io) anymore. You should always filter and sanitize data coming from user to avoid [prototype-poisoning](https://medium.com/intrinsic-blog/javascript-prototype-poisoning-vulnerabilities-in-the-wild-7bc15347c96).
95
+
96
+ ## Cookie and Headers
97
+
98
+ > [!TIP]
99
+ H3 now natively uses standard web [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) for all utils.
100
+
101
+ Header values are always a plain `string` now (no `null` or `undefined` or `number` or `string[]`).
102
+
103
+ For the [`Set-Cookie`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) header, you can use [`headers.getSetCookie`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie) that always returns a string array.
104
+
105
+ ## Other Deprecations
106
+
107
+ H3 v2 deprecated some legacy and aliased utilities.
108
+
109
+ ### App and router utils
110
+
111
+ - `createApp` / `createRouter`: Migrate to `new H3()`.
112
+
113
+ ### Error utils
114
+
115
+ - `createError`/`H3Error`: Migrate to `HTTPError`
116
+ - `isError`: Migrate to `HTTPError.isError`
117
+
118
+ ### Handler utils
119
+
120
+ - `eventHandler`/`defineEventHandler`: Migrate to `defineHandler` (you can also directly use a function!).
121
+ - `lazyEventHandler`: Migrate to `defineLazyEventHandler`.
122
+ - `isEventHandler`: (removed) Any function can be an event handler.
123
+ - `useBase`: Migrate to `withBase`.
124
+ - `defineRequestMiddleware` and `defineResponseMiddleware` removed.
125
+
126
+ ### Request utils
127
+
128
+ - `getHeader` / `getRequestHeader`: Migrate to `event.req.headers.get(name)`.
129
+ - `getHeaders` / `getRequestHeaders`: Migrate to `Object.fromEntries(event.req.headers.entries())`.
130
+ - `getRequestPath`: Migrate to `event.url.pathname`.
131
+ - `getMethod`: Migrate to `event.req.method`.
132
+
133
+ > [!NOTE]
134
+ The following `H3Event` properties are deprecated in v2 and might be removed in a future version:
135
+
136
+ > - `event.path` → use `event.url.pathname + event.url.search`
137
+ > - `event.method` → use `event.req.method`
138
+ > - `event.headers` → use `event.req.headers`
139
+ > - `event.node` → use `event.runtime.node`
140
+
141
+ ### Response utils
142
+
143
+ - `getResponseHeader` / `getResponseHeaders`: Migrate to `event.res.headers.get(name)`
144
+ - `setHeader` / `setResponseHeader` / `setHeaders` / `setResponseHeaders`: Migrate to `event.res.headers.set(name, value)`.
145
+ - `appendHeader` / `appendResponseHeader` / `appendResponseHeaders`: Migrate to `event.res.headers.append(name, value)`.
146
+ - `removeResponseHeader` / `clearResponseHeaders`: Migrate to `event.res.headers.delete(name)`
147
+ - `appendHeaders`: Migrate to `appendResponseHeaders`.
148
+ - `defaultContentType`: Migrate to `event.res.headers.set("content-type", type)`
149
+ - `getResponseStatus` / `getResponseStatusText` / `setResponseStatus`: Use `event.res.status` and `event.res.statusText`.
150
+
151
+ ### Node.js utils
152
+
153
+ - `defineNodeListener`: Migrate to `defineNodeHandler`.
154
+ - `fromNodeMiddleware`: Migrate to `fromNodeHandler`.
155
+ - `toNodeListener`: Migrate to `toNodeHandler`.
156
+ - `createEvent`: (removed): Use Node.js adapter (`toNodeHandler(app)`).
157
+ - `fromNodeRequest`: (removed): Use Node.js adapter (`toNodeHandler(app)`).
158
+ - `promisifyNodeListener` (removed).
159
+ - `callNodeListener`: (removed).
160
+
161
+ ### Web Utils
162
+
163
+ - `fromPlainHandler`: (removed) Migrate to Web API.
164
+ - `toPlainHandler`: (removed) Migrate to Web API.
165
+ - `fromPlainRequest` (removed) Migrate to Web API or use `mockEvent` util for testing.
166
+ - `callWithPlainRequest` (removed) Migrate to Web API.
167
+ - `fromWebRequest`: (removed) Migrate to Web API.
168
+ - `callWithWebRequest`: (removed).
169
+
170
+ ### Body Utils
171
+
172
+ - `readRawBody`: Migrate to `event.req.text()` or `event.req.arrayBuffer()`.
173
+ - `getBodyStream` / `getRequestWebStream`: Migrate to `event.req.body`.
174
+ - `readFormData` / `readMultipartFormData` / `readFormDataBody`: Migrate to `event.req.formData()`.
175
+
176
+ ### Other Utils
177
+
178
+ - `isStream`: Migrate to `instanceof ReadableStream`.
179
+ - `isWebResponse`: Migrate to `instanceof Response`.
180
+ - `splitCookiesString`: Use `splitSetCookieString` from [cookie-es](https://github.com/unjs/cookie-es).
181
+ - `MIMES`: (removed).
182
+
183
+ ### Type Exports
184
+
185
+ > [!NOTE]
186
+ There might be more type changes.
187
+
188
+ - `App`: Migrate to `H3`.
189
+ - `AppOptions`: Migrate to `H3Config`.
190
+ - `_RequestMiddleware`: Migrate to `RequestMiddleware`.
191
+ - `_ResponseMiddleware`: Migrate to `ResponseMiddleware`.
192
+ - `NodeListener`: Migrate to `NodeHandler`.
193
+ - `TypedHeaders`: Migrate to `RequestHeaders` and `ResponseHeaders`.
194
+ - `HTTPHeaderName`: Migrate to `RequestHeaderName` and `ResponseHeaderName`.
195
+ - `H3Headers`: Migrate to native `Headers`.
196
+ - `H3Response`: Migrate to native `Response`.
197
+ - `MultiPartData`: Migrate to native `FormData`.
198
+ - `RouteNode`: Migrate to `RouterEntry`.
199
+ `CreateRouterOptions`: Migrate to `RouterOptions`.
200
+ Removed type exports: `WebEventContext`, `NodeEventContext`, `NodePromisifiedHandler`, `AppUse`, `Stack`, `InputLayer`, `InputStack`, `Layer`, `Matcher`, `PlainHandler`, `PlainRequest`, `PlainResponse`, `WebHandler`.
@@ -0,0 +1,42 @@
1
+ # Community
2
+
3
+ > H3 utils from community.
4
+
5
+ You can use external H3 event utilities made by the community.
6
+
7
+ This section is placeholder for any new H3 version 2 compatible community library.
8
+
9
+
10
+
11
+ > [!TIP]
12
+ > 💛 PR is more than welcome to list yours.
13
+
14
+ ## `apitally`
15
+
16
+ [Apitally](https://apitally.io/h3) is a simple API monitoring, analytics, and request logging tool with a plugin for H3. See setup guide [here](https://docs.apitally.io/frameworks/h3).
17
+
18
+ <read-more></read-more>
19
+
20
+ ## `H3ravel Framework`
21
+
22
+ [H3ravel Framework](https://h3ravel.toneflix.net) is a modern TypeScript runtime-agnostic web framework built on top of H3, designed to bring the elegance and developer experience of Laravel PHP to the JavaScript ecosystem. See the getting started guide [here](https://h3ravel.toneflix.net/guide/get-started).
23
+
24
+ <read-more></read-more>
25
+
26
+ ## `Intlify`
27
+
28
+ [Intlify](https://intlify.dev/) is a project that aims to improve Developer Experience in software internationalization. That project provides server-side frameworks, middleware, and utilities. About those, see the [here](https://github.com/intlify/srvmid)
29
+
30
+ <read-more></read-more>
31
+
32
+ ## `Clear Router`
33
+
34
+ Laravel-style routing system for H3 and Express.js. Clean route definitions, middleware support, and controller bindings with full TypeScript support.
35
+
36
+ <read-more></read-more>
37
+
38
+ ## `unjwt`
39
+
40
+ `unjwt` is a collection of low-level JWT utilities (JWS, JWE, JWK) built on the Web Crypto API, with zero runtime dependencies. It includes a dedicated H3 v2 adapter for header and cookie-based session management with support for encrypted (JWE) and signed (JWS) tokens.
41
+
42
+ <read-more></read-more>