API Reference

@taserjs/router-client

Complete API reference for @taserjs/router-client: createClient options, fetch interop, formBody utilities, and end-to-end TypeScript types.

The @taserjs/router-client package provides a lightweight, zero-codegen typed proxy client that infers routes, parameter inputs, and response return shapes directly from your backend router definitions.


Core Functions

createClient<TApp>(options)

Creates an auto-completing typed proxy client. Pass your server's RouteManifest or typeof app as TApp to infer all available endpoints, parameters, query schemas, and return contracts:

function createClient<TApp = never>(options: CreateClientOptions): Client<TApp>;

Options (CreateClientOptions)

Prop

Type


formBody(fields, options?)

Encodes fields and file attachments into a FormData multipart payload tagged for TypeScript body inference:

function formBody<T extends Record<string, FormBodyField>>(
  value: T,
  options?: FormBodySerializeOptions,
): FormBody<T>;

Field Types (FormBodyField)

Prop

Type


Per-Request Options (ClientRequestOptions)

Every client method takes an optional second argument for request-specific configuration:

export type ClientRequestOptions = {
  headers?:
    Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
  fetch?: typeof fetch;
  init?: RequestInit;
};

Prop

Type


Client Proxy Calling Signatures

The client exposes methods named with $<method>:

Prop

Type


Path Segment Conventions

URL paths are accessed through property chaining on the client:

  • Dynamic Parameters (:id): Property is prefixed with _ (e.g. api.users._id.$get({ param: { id: "123" } })).
  • Wildcards (*): Property is _splat (e.g. api.assets._splat.$get({ param: { _splat: "image.png" } })).
  • Leading Dots (.well-known): Property starts with $ (e.g. api.$well_known.jwks.$get()).
  • Hyphens (user-profiles): Replaced with underscores in property names (e.g. api.user_profiles.$get()).
  • Root Route (/): Method called directly on client instance (e.g. api.$get()).
  • Literal Index (/index): Property index (e.g. api.index.$get()).

Response & Type Inference

Every client endpoint returns a ClientResponse<TJson>, which extends Web Response with a typed json() method:

export type ClientResponse<TJson = unknown> = Omit<Response, "json"> & {
  json(): Promise<TJson>;
};

Type Resolution Precedence

TJson for await res.json() is resolved automatically — .returns() is not required:

  1. Handler inference (default): When .returns() is omitted, TJson is the union of successful ReplyOf<Status, Body> types (200226) from handler reply helpers (json(), ok(), created(), etc.).
  2. returns[200] override: If the route declares .returns({ 200: schema }), TJson uses that schema's output type instead of handler inference.
  3. Fallback: unknown if neither source is available.

Exported TypeScript Types & Constants

import type {
  Client,
  CreateClientOptions,
  ClientRequestOptions,
  ClientResponse,
  FormBody,
  FormBodyField,
  FormBodyInput,
  HttpMethodName,
  InferRequestType,
  InferResponseType,
  OpenQuery,
  QueryWithOpen,
} from "@taserjs/router-client";

import { METHOD_MAP, CLIENT_METHODS, createClient, formBody } from "@taserjs/router-client";