Concepts
API routes are Worker adapters.
Native Fragments delegates API paths to any Web Standards router with a fetch method. Hono works directly, while core stays dependency-free.
Mount Hono
import { createCloudflareHandler } from "@nativefragments/core/cloudflare";
import { Hono } from "hono";
import { routes } from "./site/routes.js";
import { shell } from "./site/shell.js";
const api = new Hono();
api.get("/api/health", (context) =>
context.json({ ok: true })
);
export default createCloudflareHandler({
api,
routes,
shell
});
Change the prefix
The adapter sends /api and /api/* to the API
router by default. Use apiPrefix when an app needs a
different path.
export default createCloudflareHandler({
api,
apiPrefix: "/rpc",
routes,
shell
});