Rouzer documentation
Choose the guide that matches your next Rouzer decision, from defining a shared route contract to mounting the completed router in a Fetch runtime.
Rouzer combines a shared TypeScript route tree, a fetch-compatible server router, a typed fetch client, and request context composition. The guides keep those concerns separate while showing where they meet.
Learning Path
- Read Framework concepts for the lifecycle and boundaries.
- Read Route contracts to declare resources, actions, schemas, and metadata.
- Read Middleware and request context before writing shared context, auth, environment, tracing, or runtime-specific middleware.
- Read Routers and handlers to attach route trees and implement handlers.
- Read Typed client to call the same route tree from application code.
- Read Responses, errors, and plugins and NDJSON streaming when routes need more than a simple JSON success body.
- Read Runtime and adapters when mounting Rouzer in a server or test harness.
- Read Patterns, constraints, and migrations before settling on a project structure or reviewing an integration.
Important
Upgrading an existing v5 application is a different path. Start with Migration from v5 to v6, then return to the focused guides when a changed boundary needs more detail.
Guide Map
| Guide | Concern |
|---|---|
| Framework concepts | The high-level model, request lifecycle, and Rouzer's framework responsibilities. |
| Route contracts | rouzer/http resources, actions, Zod schemas, raw bodies, path patterns, and metadata. |
| Middleware and request context | chain, request plugins, RequestContext, context.host, env access, waitUntil, onResponse, passThrough, isolation, and runtime filtering. |
| Routers and handlers | createRouter, route handler maps, validated handler context, CORS, debug mode, middleware ordering, and handler return values. |
| Typed client | createClient, generated action functions, flat input objects, headers, custom fetch, onJsonError, and lifecycle hooks. |
| Responses, errors, and plugins | $type, $error, response maps, status tuples, custom Response returns, and response plugin contracts. |
| NDJSON streaming | Streaming response markers, router/client plugin registration, cancellation, and stream error modeling. |
| Runtime and adapters | Root toFetchHandler, fetch-compatible mounting, custom host data, tests, CORS, and background work. |
| Patterns, constraints, and migrations | Preferred project structure, common constraints, and migration notes from older Rouzer shapes. |
| Migration from v5 to v6 | Hattip-compatible to fetch-compatible server mounting, type, test, host data, and runtime-filter updates. |
Request Lifecycle
The route tree is the shared contract. The client uses it to construct the request, and the router uses it to validate and dispatch that request.
After response callbacks finish, the Fetch-compatible handler returns the final
Web Response to the runtime.
Runnable Examples
| Example | Shows |
|---|---|
| Shared route, router, and client | A complete JSON route from declaration through a client call. |
| Declared status responses | Typed success and error tuples from a response map. |
| NDJSON response stream | Plugin registration, streaming, and incremental consumption. |
Framework Surface
Rouzer owns:
- route tree declarations and handler/client type inference
- request validation from route schemas
- route matching and handler dispatch
- response markers, response maps, and response plugin integration
- generated client action functions
Rouzer middleware and runtime helpers cover:
- middleware chaining and short-circuit behavior
- request context creation and extension
- host data such as
context.host.ipandcontext.host.runtime - typed environment access through
context.env(...) waitUntil,setHeader,onResponse,passThrough, and chain isolation- adapter helpers such as
toFetchHandler