Function: createRpcClient()
createRpcClient<
T>(doBindingName,doInstanceNameOrId,options?):T&RpcClientProxy
Defined in: packages/rpc/src/client.ts:35
Creates an RPC client that proxies method calls to a remote Durable Object. Connection is established automatically on first method call (lazy connection) and auto-reconnected on first call after disconnect.
Use 'await using' for automatic cleanup, or manually manage lifecycle.
Type Parameters
T
T
The type of the Durable Object being called. Use RpcAccessible to expose protected properties like ctx and env.
Parameters
doBindingName
string
The DO binding name from wrangler.jsonc (e.g., 'MY_DO')
doInstanceNameOrId
string
The DO instance name or ID
options?
Optional configuration (transport, baseUrl, headers, etc.)
Returns
T & RpcClientProxy
A proxy object with both lifecycle methods and DO method calls
Remarks
This is a factory function that returns an instance of the internal RpcClient class.
The factory pattern provides a cleaner API (no new keyword) and allows for easier
API evolution without breaking changes. For testing, use createTestingClient
which provides sensible defaults for the Cloudflare Workers test environment.
See
Usage Examples - Complete tested examples