CORE CONCEPTS
Express Adapter
toExpressHandler() bridges Futon's Web-standard fetch() pipeline to an Express (req, res, next) handler — useful when you're incrementally adopting Futon inside an existing Express app.
Usage
import express from 'express'; import { Futon, toExpressHandler, json } from '@rasenganjs/futon'; const app = new Futon(); app.get('/api/health', async () => json({ status: 'ok' })); const expressApp = express(); expressApp.use(toExpressHandler(app)); expressApp.listen(3000);
What It Does
- Reads the Express
req(method, URL, headers, body) and constructs a Web APIRequest. - Calls
app.fetch(request, runtime)— the exact same entry point every other adapter uses. - Writes the resulting
Response's status, headers, and body back onto the Expressres.
If Express's own body-parsing middleware already consumed req.body, the adapter re-serializes it as JSON before handing it to Futon — otherwise it streams the raw Node IncomingMessage through as a Web ReadableStream.
Streaming Responses
For SSR or any streamed response body, the adapter pipes the Web Response body directly to the Express response socket chunk-by-chunk rather than buffering the whole thing first — this is what makes streamResponse() work transparently under Express too.
Error Handling
Any error thrown while building the request or running app.fetch() is forwarded to Express's own next(error) — so your existing Express error-handling middleware still applies as a final safety net, in addition to Futon's own onError().
