Skip to content
oRPC
Esc
navigateopen⌘Jpreview
On this page

DynamicLink

DynamicLink lets you choose a link at runtime. Use it when different requests should be routed through different links.

Example

import { function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T
Creates a fully typed oRPC client from a link. The returned client mirrors the shape of your router or contract, so calling a procedure is as simple as calling a function.
@see{@link https://orpc.dev/docs/client/client-side Client-Side Clients}
createORPCClient
, class DynamicLink<TClientContext extends ClientContext>
DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks based on the request path, input, and context.
@see{@link https://orpc.dev/docs/client/dynamic-link DynamicLink}
DynamicLink
} from '@orpc/client'
interface ClientContext { ClientContext.cache?: boolean | undefinedcache?: boolean } const const cacheLink: RPCLink<ClientContext>cacheLink = new new RPCLink<ClientContext>(options: RPCLinkOptions<ClientContext>): RPCLink<ClientContext>
Client link that communicates with an RPC Handler over the Fetch API (HTTP).
@see{@link https://orpc.dev/docs/adapters/fetch-api Fetch API Adapter}
RPCLink
({
FetchLinkTransportOptions<ClientContext>.origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [options: ClientOptions<ClientContext>, path: string[]]>
The origin to prepend to all request URLs, useful for CORS requests.
@example'https://api.example.com'@example'http://localhost:3000'
origin
: 'https://cache.example.com',
}) const const noCacheLink: RPCLink<ClientContext>noCacheLink = new new RPCLink<ClientContext>(options: RPCLinkOptions<ClientContext>): RPCLink<ClientContext>
Client link that communicates with an RPC Handler over the Fetch API (HTTP).
@see{@link https://orpc.dev/docs/adapters/fetch-api Fetch API Adapter}
RPCLink
({
FetchLinkTransportOptions<ClientContext>.origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [options: ClientOptions<ClientContext>, path: string[]]>
The origin to prepend to all request URLs, useful for CORS requests.
@example'https://api.example.com'@example'http://localhost:3000'
origin
: 'https://example.com',
}) const const link: DynamicLink<ClientContext>link = new new DynamicLink<ClientContext>(linkResolver: (options: ClientOptions<ClientContext>, path: string[], input: unknown) => Promisable<ClientLink<ClientContext>>): DynamicLink<ClientContext>
DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks based on the request path, input, and context.
@see{@link https://orpc.dev/docs/client/dynamic-link DynamicLink}
DynamicLink
<ClientContext>((options: ClientOptions<ClientContext>options, path: string[]path, input: unknowninput) => {
if (options: ClientOptions<ClientContext>options.ClientOptions<ClientContext>.context: ClientContextcontext?.ClientContext.cache?: boolean | undefinedcache) { return const cacheLink: RPCLink<ClientContext>cacheLink } return const noCacheLink: RPCLink<ClientContext>noCacheLink }) const
const client: {
    ping: ProcedureClient<ClientContext, InitialInputSchema, Schema<string>, Record<never, never>, never>;
    pong: ProcedureClient<ClientContext, InitialInputSchema, Schema<string>, Record<never, never>, never>;
}
client
: type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = object> = TRouter extends Procedure<any, any, infer $InputSchema extends AnySchema, infer $OutputSchema extends AnySchema, infer $ErrorMap extends ErrorMap, infer $ReturnedError extends AnyORPCError> ? ProcedureClient<TClientContext, $InputSchema, $OutputSchema, $ErrorMap, $ReturnedError> : { [K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<...> : never; }
The client type derived from a router, exposing every procedure as a callable function while preserving the router's shape.
@see{@link https://orpc.dev/docs/client/client-side#creating-a-client Client-Side Clients - Creating a Client}
RouterClient
<typeof
const router: {
    ping: DecoratedProcedure<DefaultInitialContext & object, object, InitialInputSchema, Schema<string>, Record<never, never>, never>;
    pong: DecoratedProcedure<DefaultInitialContext & object, object, InitialInputSchema, Schema<string>, Record<never, never>, never>;
}
router
, ClientContext> =
createORPCClient<{
    ping: ProcedureClient<ClientContext, InitialInputSchema, Schema<string>, Record<never, never>, never>;
    pong: ProcedureClient<ClientContext, InitialInputSchema, Schema<string>, Record<never, never>, never>;
}>(link: ClientLink<ClientContext>, { path, ...options }?: NoInfer<ORPCClientOptions<{
    ping: ProcedureClient<ClientContext, InitialInputSchema, Schema<string>, Record<never, never>, never>;
    pong: ProcedureClient<ClientContext, InitialInputSchema, Schema<string>, Record<never, never>, never>;
}>>): {
    ping: ProcedureClient<ClientContext, InitialInputSchema, Schema<string>, Record<never, never>, never>;
    pong: ProcedureClient<ClientContext, InitialInputSchema, Schema<string>, Record<never, never>, never>;
}
Creates a fully typed oRPC client from a link. The returned client mirrors the shape of your router or contract, so calling a procedure is as simple as calling a function.
@see{@link https://orpc.dev/docs/client/client-side Client-Side Clients}
createORPCClient
(const link: DynamicLink<ClientContext>link)

Last updated on August 6, 2026

Was this page helpful?