ORPC Client Setup
The ORPC client provides end-to-end type safety for your RPC calls, ensuring that client code stays in sync with server-side router definitions.Client Configuration
The ORPC client is configured insrc/utils/orpc.ts using createORPCClient with an RPCLink for HTTP communication.
Basic Setup
RPCLink Configuration
URL
The RPC endpoint URL is constructed from theNEXT_PUBLIC_SERVER_URL environment variable:
/rpc/[...all].
Headers
Headers are handled differently for server-side and client-side requests:- Server-side: Forwards cookies and authentication headers from the incoming request
- Client-side: Browser automatically handles cookies, no manual header forwarding needed
Credentials
Thecredentials: "include" setting ensures cookies are sent with every request:
Type-Safe Client
The client is strongly typed usingRouterClient<typeof appRouter>:
- Full type inference for all RPC methods
- Autocomplete for available procedures
- Type checking for input parameters and return values
- Compile-time errors if server API changes
Calling RPC Methods
Server-Side Usage
In Server Components and Server Actions, call RPC methods directly:src/app/server/page.tsx:11:
Client-Side Usage
On the client, use the client with TanStack Query (see TanStack Query integration):Type Inference
The client automatically infers types from your router definition:- Pass incorrect parameter types
- Forget required parameters
- Try to access non-existent procedures
Available Procedures
Based on yourappRouter definition:
Error Handling
The client throws typed errors that you can catch:Next Steps
- Learn about TanStack Query integration for React hooks
- Explore creating custom procedures
- See authentication setup for protected routes