A router is a plain JavaScript object where the values are procedures or nested routers. oRPC traverses this object to route incoming requests to the correct procedure.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/middleapi/orpc/llms.txt
Use this file to discover all available pages before exploring further.
Defining a router
You can define a router by composing procedures into an object:Using os.router()
The os.router() method lets you apply shared options (middleware, error maps, prefix, tags) to an entire router:
os.router() returns a new router with the middleware and options merged into every procedure. The original procedures are not mutated.Nested routers
Combine multiple routers to build your full API:Prefixing routes
When serving an OpenAPI spec, you can add a URL prefix to all procedures in a router:Prefixes only affect procedures that define an explicit
route with a path. They are ignored for procedures served via the default RPC path convention.Tagging procedures for OpenAPI
Add OpenAPI tags to all procedures in a router at once:Router utility types
@orpc/server exports several utility types for introspecting your router:
Lazy routers
For large routers that impact cold start times, you can wrap sub-routers inlazy() to defer loading until first use. See Lazy Routers for details.
