Router from Client
Turn an oRPC client into a router with createRouterFromClient.
Overview
createRouterFromClient turns a client into a router that forwards every call to it. Use the router anywhere a router is accepted, such as a handler:
import { createRouterFromClient } from '@orpc/server'
const router = createRouterFromClient(contract, client)
contract can be a contract or a router without lazy children. A router’s handlers and middlewares are ignored.
Context
The router context is passed to the client as its client context:
const client: RouterContractClient<typeof contract, { token: string }> = createORPCClient(link)
const router = createRouterFromClient(contract, client)
const handler = new RPCHandler(router)
await handler.handle(request, {
context: { token: 'token' }, // <- the client context
})
Validation
The router does not validate input, output or errors, it just forwards calls to the client. For validation, consider the Request Validation and Response Validation plugins on the client’s link.