Big Marge runtime
Generated runtime
Section titled “Generated runtime”The big-marge registry item writes a Durable Object with health and message endpoints:
export class BigMarge { constructor( readonly ctx: DurableObjectState, readonly env: Env ) {}
async fetch(request: Request): Promise<Response> { const url = new URL(request.url);
if (request.method === 'GET' && url.pathname === '/health') { return Response.json({ ok: true, durableObject: 'big-marge' }); }
if (request.method === 'POST' && url.pathname === '/message') { const body = (await request.json()) as { message?: string }; return Response.json({ reply: body.message ? `Big Marge heard: ${body.message}` : 'Big Marge is listening.', }); }
return new Response('Not found', { status: 404 }); }}The generated helper resolves a stable named instance:
export function getBigMargeStub(env: Env, id = 'primary') { return env.BIG_MARGE.get(env.BIG_MARGE.idFromName(id));}Wrangler changes
Section titled “Wrangler changes”The registry manifest adds the equivalent of:
{ "durable_objects": { "bindings": [ { "name": "BIG_MARGE", "class_name": "BigMarge" } ] }, "r2_buckets": [ { "binding": "BIG_MARGE_BUCKET", "bucket_name": "big-marge", "remote": true } ], "vars": { "BIG_MARGE_DEFAULT_PERSONA": "large-and-in-charge" }, "migrations": [ { "tag": "<generated>", "new_sqlite_classes": ["BigMarge"] } ]}Finish integration
Section titled “Finish integration”-
Export the class from your Worker entrypoint
export { BigMarge } from './big-marge'; -
Route requests to a named stub
import { getBigMargeStub } from './big-marge';export default {fetch(request, env) {return getBigMargeStub(env).fetch(request);},} satisfies ExportedHandler<Env>; -
Create or verify the R2 bucket before deploying if your environment does not provision it separately.