RPCLink
RPCLink (from @orpc/client/fetch) is the standard link for communicating with an oRPC server over HTTP using the oRPC binary protocol.
Options
| Option | Type | Description |
|---|---|---|
url | string | URL | The base URL of your oRPC handler. |
headers | HeadersInit | (path, input) => HeadersInit | Promise<HeadersInit> | Static or dynamic headers sent with every request. |
fetch | (request, init, options, path, input) => Promise<Response> | Custom fetch function — override for mocking, retries, or environments without a global fetch. |
plugins | LinkFetchPlugin[] | Link plugins (see below). |
interceptors | Interceptor[] | Low-level request/response interceptors. |
clientInterceptors | Interceptor[] | Interceptors that run just before and after the HTTP call. |
Adding authorization headers
headers option can be a function so that the token is read fresh on every request.
Custom fetch function
Abort signals
Pass a signal per call to cancel inflight requests:DynamicLink
DynamicLink lets you choose which link to use at call time, based on the procedure path, input, or context. This is useful when you want to route some procedures to a different server or use a different protocol.
options—ClientOptions(includescontextandsignal)path— the procedure path as areadonly string[]input— the raw input value
Promise.
Client plugins
Plugins extend links with cross-cutting behaviour. Pass them in theplugins array when constructing an RPCLink.
ClientRetryPlugin
Automatically retries failed calls. Supports configurable delays, retry counts, and ashouldRetry predicate.
retry accepts Number.POSITIVE_INFINITY for event iterator (SSE) connections that should reconnect indefinitely.
Other built-in plugins
All plugins are imported from@orpc/client/plugins:
| Plugin | Description |
|---|---|
BatchLinkPlugin | Batches multiple procedure calls into a single HTTP request. |
DedupeRequestsPlugin | Deduplicates identical in-flight requests. |
RetryAfterPlugin | Respects the Retry-After header from 429/503 responses. |
SimpleCsrfProtectionLinkPlugin | Adds a custom header to guard against CSRF attacks. |
Interceptors
For lower-level control, useinterceptors or clientInterceptors on RPCLink:
