Handler Functions
Handler functions give you full programmatic control over a route response. You export async functions from a yrest.handlers.js file; yRest loads them at startup and calls the matching function when the route is hit. Unlike scenarios, handlers can run any logic — counters, state, conditional branching, external calls.
The handler file
Section titled “The handler file”Function signature
Section titled “Function signature”Referencing a handler in _routes
Section titled “Referencing a handler in _routes”Fallback to response:
Section titled “Fallback to response:”CLI scaffold command
Section titled “CLI scaffold command”Async handlers
Section titled “Async handlers”TypeScript support
Section titled “TypeScript support”Examples
Section titled “Examples”Next steps
Section titled “Next steps”- Scenarios — simpler conditional responses without code
- SSE Streams — handler-based SSE streams (Phase 12B)
- CLI Reference —
yrest handlercommand reference