What problem does it solve?
This guide explains how to invoke tRPC procedures directly from server code to run integration tests, implement internal server logic, and expose server-only API endpoints without an HTTP layer.
Core Features & Use Cases
- Direct caller creation: Use createCallerFactory or router.createCaller to invoke procedures with a fully-formed server context.
- Integration testing: Execute procedures in tests with simulated contexts to validate behavior without running an HTTP server.
- Error handling for APIs: Catch TRPCError and map it to HTTP status codes using getHTTPStatusCodeFromError and optionally observe errors with onError callbacks.
- Best practices: Avoid creating callers inside procedures; extract shared logic into plain functions and supply proper context when calling protected routes.
Quick Start
Create a caller with createCallerFactory using a test context that includes a simulated user and call post.list to retrieve posts.