TypeScript Client

API reference for the TypeScript client.

createClient

import { createClient, httpBatchLink } from "@pyrpc/client"
import type { Types } from "@pyrpc/types"

const client = createClient<Types>({
  links: [
    httpBatchLink({
      url: "https://api.example.com",
    }),
  ],
})

Creates a typed proxy that maps each procedure name to an async function. All procedure calls return Promise<T>.

Options

interface ClientOptions {
  links: Link[]
}
OptionDescription
linksLink pipeline. Exactly one terminating link (httpLink or httpBatchLink); zero or multiple is a configuration error.

httpLink sends one RPC operation per HTTP request.

httpLink({ url: "https://api.example.com" })
OptionDescription
urlServer URL. The link normalizes to /rpc.

httpBatchLink combines multiple independent RPC operations that occur close together into one HTTP request.

httpBatchLink({ url: "https://api.example.com", maxItems: 10 })
OptionDescription
urlServer URL. The link normalizes to /rpc.
maxItemsMax operations per batch; flushed early when reached. Defaults to Infinity.

Batched operations execute sequentially on the server and each keeps its own result or error. A batch is not a transaction.

Usage

const client = createClient<Types>({
  links: [
    httpBatchLink({
      url: "https://api.example.com",
    }),
  ],
})

// Fully typed, parameters and return type inferred from the server
const result = await client.add(10, 5)