Skip to Content
TypeScript SDKServe

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 basePath used in initServe().
  • 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.

On this page

Get early access to hypequery cloud.

Cloud hosts the same model you run in your backend, with a managed API and MCP server, versions, and rollback. We're letting teams in a few at a time. Join the waitlist and we'll reach out when your project can go live.

How do you want to build your analytics layer? (Optional)
What features do you most need? (Optional)

Pick as many as you like.

Only your email is required. All other questions are optional.