Cloudflare Workers Expert Guide
Use this skill when building, refactoring, or optimizing Cloudflare Workers.
Key Architecture Principles
- Zero Cold Starts: Target sub-5ms response times.
- ES Modules Syntax: Always export default with
fetch(request, env, ctx). - Bindings: Inject KV, D1, R2, Queues, and AI bindings via
env. Never hardcode secrets. - Streaming: Stream responses via
TransformStreamfor large payloads or LLM completions.
Standard Worker Structure
typescriptexport interface Env { DB: D1Database; CACHE: KVNamespace; API_SECRET: string; } export default { async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { const url = new URL(request.url); if (request.method === "GET" && url.pathname === "/health") { return new Response(JSON.stringify({ status: "healthy" }), { headers: { "Content-Type": "application/json" } }); } return new Response("Not Found", { status: 404 }); } };
AgenticMarket