Skip to content

feat: support universal { fetch } handlers#1210

Merged
pi0 merged 2 commits intomainfrom
feat/fetchable-handler
Sep 30, 2025
Merged

feat: support universal { fetch } handlers#1210
pi0 merged 2 commits intomainfrom
feat/fetchable-handler

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Sep 30, 2025

H3 by default supports (event: H3Event) => any handler format.

For better external compatibility, we have introduced app.mount(<base>, <fetchable>) where it is possible to mount an external framework like Elysia or Hono, or simply use { fetch(req: Request) => Response } universal alternative format.

This PR adds Fetchable object format support for also h3App[method]("route", <fetchable>) and defineHandler.

import { H3 } from "h3";

const app = new H3();

app.get("/hello/:id", {
  fetch: (req) => new Response("Standards FTW!"),
});

export default app;

This is particularly useful to be used together with filesystem routing like Nitro to mount any standard fetchable handler, also via filesystem routes.

// routes/hello/[id].ts

// Standard handler
import { defineHandler } from "h3"
export default defineHandler({
  fetch: (req) => new Response("Standards FTW!"),
})

// Hono (https://hono.dev/)
import { Hono } from "hono";
export default new Hono().get("/", (c) =>
   c.text("Hello from server entry (Hono)!")
 );

// Elysia (https://elysiajs.com/)
import { Elysia } from "elysia";
export default new Elysia().get("/", () => "Hello from server entry (Elysia)!");

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/handler.ts 88.88% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@pi0 pi0 merged commit 631249d into main Sep 30, 2025
5 checks passed
@pi0 pi0 deleted the feat/fetchable-handler branch September 30, 2025 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant