How to ship a Cloudflare Worker API with D1 backing
When to use: You want a small JSON API with auth and persistence, deployed to Cloudflare.
Flow
-
ScaffoldUse the Cloudflare skill. New Worker with D1 binding, Hono router, routes: GET /todos, POST /todos, DELETE /todos/:id.✓ Copied→ Worker code + wrangler.toml + schema.sql
-
AuthAdd bearer token auth using a secret in env.✓ Copied→ Middleware + wrangler secret put instructions
-
Deploywrangler d1 execute + wrangler deploy steps.✓ Copied→ Live URL after deploy
Outcome: A deployed Worker API with D1 persistence.
Pitfalls
- D1 migrations drift between envs — Use wrangler d1 migrations create + apply; don't ad-hoc exec