Back to Exercises
Worker Service
Build a Cloudflare Worker that composes cleanly with other services.
Objectives
- Design a clean service interface
- Implement proper error handling
- Use service bindings for composition
- Follow gateway pattern principles
Beads Tasks
Create these tasks in Beads before starting. You learn Beads by using Beads.
bd create "Praxis: Build [service] Worker" --type=feature--labels=learn,infrastructurebd create "Design service interface (inputs, outputs, errors)" --type=task--labels=learnbd create "Implement core handler logic" --type=task--labels=learnbd create "Add error handling with proper HTTP semantics" --type=task--labels=learnbd create "Configure service bindings for composition" --type=task--labels=learnbd create "Test end-to-end with wrangler dev" --type=task--labels=learnClaude Code Prompt
Copy this prompt into Claude Code to build YOUR own version:
## Setup: Track this exercise with Beads ```bash bd create "Praxis: Build [service] Worker" --type=feature --labels=learn,infrastructure bd create "Design service interface (inputs, outputs, errors)" --type=task --labels=learn bd create "Implement core handler logic" --type=task --labels=learn bd create "Add error handling with proper HTTP semantics" --type=task --labels=learn bd create "Configure service bindings for composition" --type=task --labels=learn bd create "Test end-to-end with wrangler dev" --type=task --labels=learn ``` --- Help me build a Cloudflare Worker for [SERVICE_NAME] following MY service composition patterns. I'm defining MY approach to edge services. For [SERVICE_NAME]: 1. **Design the service interface**: - What are the inputs (request shape, query params, headers)? - What are the outputs (response shape, status codes)? - What errors can occur and how are they represented? - Create a TypeScript interface for Request/Response 2. **Implement the handler**: - Parse and validate inputs - Execute core logic - Return structured responses - Use proper HTTP semantics (GET for reads, POST for mutations) 3. **Error handling strategy**: - Map internal errors to HTTP status codes - Return consistent error response shape - Log appropriately for observability 4. **Composition with bindings**: - What other services does this need? (D1, KV, R2, other Workers) - Configure wrangler.toml bindings - Use service bindings for Worker-to-Worker calls 5. **Document MY service patterns**: - Naming conventions for Workers - Standard response envelope shape - Error handling philosophy Service to build: [YOUR_SERVICE_NAME] Purpose: [WHAT_IT_DOES] Bindings needed: [D1/KV/R2/OTHER_WORKERS]
Your Solution
Write code that addresses the objectives above. Apply the principles from the Infrastructure path.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15