13 · Integrations
Cloudflare Durable Objects
Stateful primitives on the edge. c.env exposes the binding; the Durable Object class exports next to the app.
Code
cloudflare-durable-objects.js
import { WebApp } from class="tk-str">39;@hyperbridge/forge/server39;; const app = new WebApp(); app.get(class="tk-str">39;/counter39;, async (c) => { const id = c.env.COUNTER.idFromName(class="tk-str">39;global39;); const obj = c.env.COUNTER.get(id); return obj.fetch(new Request(class="tk-str">39;http:class="tk-cm">//x/inc39;)); }); export class Counter { constructor(state) { this.state = state; } async fetch(req) { let n = (await this.state.storage.get(class="tk-str">39;n39;)) ?? 0; n++; await this.state.storage.put(class="tk-str">39;n39;, n); return Response.json({ n }); } } export default app;
How it works
WebApp is just a Fetch-API handler — export it as the default and Cloudflare Workers runs it directly. No adapter shim.
Durable Objects give you single-instance, strongly-consistent state — perfect for game lobbies, rate limiters, real-time presence, collaborative documents.
c.env.COUNTER is the binding declared in wrangler.toml. Every request that should hit the same DO uses idFromName(stableKey).
Try it
Quickstart
wrangler dev → curl http://localhost:8787/counter
Related modules
This is HBForge's port of Hono's example. Read the original at hono.dev/examples/cloudflare-durable-objects.