Fetch Runtime Integration
Mount hypequery in Hono, Cloudflare Workers, Bun, Deno, React Router, SvelteKit, or any Fetch-based runtime.
This guide assumes you already have a Serve api, exported here from analytics/api.ts. If not, start with the
Quick Start.
createFetchHandler(api.handler) turns the API into a function from a Fetch Request to a Response, so any runtime
or framework that hands you a Request can serve it. Mount it under the same prefix as the basePath you gave
initServe().
Hono
// app.ts
import { Hono } from 'hono';
import { createFetchHandler } from '@hypequery/serve';
import { api } from './analytics/api.js';
const app = new Hono();
const hypequery = createFetchHandler(api.handler);
app.all('/api/analytics/*', (c) => hypequery(c.req.raw));
export default app;To run Hono on Node.js, see Node.js.
Cloudflare Workers
Export the handler as the Worker's fetch:
// src/worker.ts
import { createFetchHandler } from '@hypequery/serve';
import { api } from './analytics/api.js';
export default {
fetch: createFetchHandler(api.handler),
};Bun and Deno
Both built-in servers take a Fetch handler directly:
import { createFetchHandler } from '@hypequery/serve';
import { api } from './analytics/api.js';
const handler = createFetchHandler(api.handler);
// Bun
Bun.serve({ port: 3000, fetch: handler });
// Deno
Deno.serve({ port: 3000 }, handler);React Router
In React Router v7 (and Remix), a resource route's loader answers GET and its action every other method:
// app/routes/api.analytics.$.ts
import { createFetchHandler } from '@hypequery/serve';
import { api } from '~/analytics/api';
const handler = createFetchHandler(api.handler);
export const loader = ({ request }: { request: Request }) => handler(request);
export const action = ({ request }: { request: Request }) => handler(request);SvelteKit
A catch-all server route with fallback answers every method:
// src/routes/api/analytics/[...path]/+server.ts
import type { RequestHandler } from './$types';
import { createFetchHandler } from '@hypequery/serve';
import { api } from '$lib/analytics/api';
const handler = createFetchHandler(api.handler);
export const fallback: RequestHandler = ({ request }) => handler(request);Notes
- Keep the mounted prefix aligned with the
basePathused ininitServe(). - Use
api.run(...)when you want in-process execution instead of HTTP; see Embedded runtime. - For Next.js, see Next.js. For Express, Fastify, or a plain Node.js server, see Node.js.