@ogygia/router · API
@ogygia/router/api
The typed fetch client for a route table's endpoints.
On this page
This page is generated from the package’s own .d.ts files on every build, so the signatures, descriptions and examples below always match the source. Where a description differs from the guide, the guide is right; see Where the API page is older than this guide.
Exports api · ApiError · ApiClient · ApiClientOptions
import { … } from '@ogygia/router/api';api
function
A typed fetch client for a router's endpoints, from the app's $infer map. Paths are the keys
that have the verb; params is required when the pattern has any; the body is the schema's
input; the result is the handler's plain return (a raw Response return types as unknown).
A non-2xx answer throws ApiError. It loads only the path grammar, so islands can use it.
const cms = api<App>('https://cms.example.com');
const post = await cms.get('/posts/[id]', { params: { id: '1' } });function api<App>(base: string, opts?: ApiClientOptions): ApiClient<App>;class ApiError extends Error {/*…*/}readonly status: number;readonly body: unknown;constructor(status: number, body: unknown, message?: string);interface ApiClient<App> {/*…*/}get<K extends KeysWith<App, "get">>(path: K, ...args: CallArgs<K>): Promise<OutOf<App, K, "get">>;delete<K extends KeysWith<App, "delete">>(path: K, ...args: CallArgs<K>): Promise<OutOf<App, K, "delete">>;post<K extends KeysWith<App, "post">>(path: K, ...args: CallArgs<K, InOf<App, K, "post">>): Promise<OutOf<App, K, "post">>;put<K extends KeysWith<App, "put">>(path: K, ...args: CallArgs<K, InOf<App, K, "put">>): Promise<OutOf<App, K, "put">>;patch<K extends KeysWith<App, "patch">>(path: K, ...args: CallArgs<K, InOf<App, K, "patch">>): Promise<OutOf<App, K, "patch">>;ApiClientOptions
interface
ApiClientOptions.headers
Extra headers on every call (auth tokens, signed hops — compose with sign_headers).
ApiClientOptions.fetch
Custom fetch (a Kit event's cookie-forwarding fetch, a test stub). Default: global.
interface ApiClientOptions {/*…*/}headers?: Record<string, string>;fetch?: typeof fetch;