Skip to main content
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

Path matching is exact - /api/users will not match /api/users/123.

Custom Matcher Function

Handler Functions

Synchronous Response

Return a Response directly:

Effect-based Response

Return an Effect for async operations or context requirements:

Type Signatures

Complete Example

Request Access

The handler function receives the incoming Request 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 by createFetchHandler and return a 500 response. See Fetch Handler for details.