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[]
}| Option | Description |
|---|---|
links | Link pipeline. Exactly one terminating link (httpLink or httpBatchLink); zero or multiple is a configuration error. |
httpLink
httpLink sends one RPC operation per HTTP request.
httpLink({ url: "https://api.example.com" })| Option | Description |
|---|---|
url | Server URL. The link normalizes to /rpc. |
httpBatchLink
httpBatchLink combines multiple independent RPC operations that occur close together into one HTTP request.
httpBatchLink({ url: "https://api.example.com", maxItems: 10 })| Option | Description |
|---|---|
url | Server URL. The link normalizes to /rpc. |
maxItems | Max 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)
pyRPC