pyRPC
Reference

TypeScript Client

API reference for the TypeScript client.

TypeScript Client Reference

createClient

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

const client = createClient<Types>()

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

Options

interface ClientOptions {
  baseUrl?: string
  headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>)
}
OptionDescription
baseUrlServer base URL. Defaults to current origin + /rpc in browser environments.
headersOptional headers, can be static or async factory function.

Usage

const client = createClient<Types>()

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

PyRPCError

import { PyRPCError } from "@pyrpc/client"

Thrown when the server returns a JSON-RPC error response.

PropertyTypeDescription
codenumberJSON-RPC error code
messagestringError message
dataanyOptional error data payload

Further Reading

See the Building a full-stack app with pyRPC tutorial for a complete TypeScript client example.