basicHandler creates path-based HTTP handlers that can return responses synchronously or as Effect computations.
Usage
Path Matching
Paths can be defined as strings or custom matcher functions:String Paths
/api/users will not match /api/users/123.
Custom Matcher Function
Handler Functions
Synchronous Response
Return aResponse directly:
Effect-based Response
Return anEffect for async operations or context requirements:
Type Signatures
Complete Example
Request Access
The handler function receives the incomingRequest object:
When using Effect-based handlers, you can return
Promise<Response> directly without wrapping in Effect.tryPromise - the framework handles this automatically.Error Handling
Errors in handlers are caught automatically bycreateFetchHandler and return a 500 response. See Fetch Handler for details.