Add Forge

Create Forge once and mount its middleware before paymentMiddleware and before your /openapi.json route:
Nothing else changes: your route config, facilitator, handlers and Bazaar extensions stay as they are.

What changes on the wire

Your handlers can keep using res.json, res.send, express.static or res.sendFile. Forge works with all of them.

Complete example

A text-statistics API on Base, paid through the CDP facilitator. Forge lines are marked (forge). From examples/express-x402 in the Forge SDK repository.
server.ts
Run it:
The weather API in examples/weather is a larger Express example: two paid routes, Bazaar discovery, a static OpenAPI document and input validation before payment. It’s the service we use to test agents.