Before You Start
Always open an issue using the Experiment idea template to discuss your experiment with maintainers before implementing it.
What Makes a Good Experiment?
A good experiment:- Demonstrates a specific Cloudflare capability (Workers AI, Browser Rendering, D1, KV, R2, etc.)
- Solves a real developer need (not just “Hello World”)
- Is edge-first and runs in under 60 seconds
- Has a single responsibility (one experiment = one capability)
- Is independently deployable without dependencies on other experiments
- Provides practical value that developers would actually use
Step-by-Step Process
Open an experiment idea issue
Use the Experiment idea template to propose your experiment. Include:
- What Cloudflare capability it demonstrates
- What problem it solves
- Basic description of how it works
- Any special bindings or resources needed (D1, KV, AI, etc.)
Create the experiment directory
Create a new directory under Use kebab-case for the experiment name (e.g.
experiments/<name>/:is-it-down, link-shortener).Set up the project structure
Create the standard directory structure:Your directory should look like:
Initialize package.json
Create a Then install dependencies:
package.json with the required dependencies:Create wrangler.toml
Configure your Worker with Or use
wrangler.toml:wrangler.json if you prefer JSON format.Implement the Worker
Follow the code standards to implement your Worker:Create Create Create Create your route handlers in Create
src/types/env.d.ts:src/utils/response.ts:src/lib/url.ts (if handling URL params):src/routes/:src/index.ts:Test locally
Run your experiment locally:Test your endpoints:Verify:
- All routes work as expected
- Error handling works correctly
- TypeScript has no errors
Common Patterns and Examples
Using Reference Experiments
You can use existing experiments as references:Simple stateless experiment
Simple stateless experiment
Reference:
whereami or is-it-downThese experiments:- Don’t use persistent storage
- Have simple route handlers
- Focus on edge networking
Experiment with database
Experiment with database
Reference:
link-shortenerThis experiment:- Uses D1 for primary storage
- Uses KV for read cache
- Handles database errors gracefully
- Implements retry logic for unique constraints
Experiment with AI
Experiment with AI
Reference:
ai-website-summary or github-repo-explainerThese experiments:- Use Workers AI binding
- Handle streaming responses
- Process external content
Experiment with Browser Rendering
Experiment with Browser Rendering
Reference:
screenshot-apiThis experiment:- Uses Browser Rendering API
- Handles binary responses (images)
- Implements proper timeouts
Error Handling Patterns
Handling fetch errors:Deployment Checklist
Before submitting your PR, verify:-
npm run devworks locally -
npx wrangler deploydeploys successfully - All endpoints return proper JSON responses
- Error codes are descriptive (e.g.
INVALID_URL, notERROR) - Global error handler returns consistent 500 responses
- README.md documents all API endpoints
- Bindings are declared in both
wrangler.tomlandsrc/types/env.d.ts - TypeScript strict mode passes with no errors
- No
anytypes in the code - Added experiment to root README.md table
Getting Help
What if I'm not sure which Cloudflare feature to use?
What if I'm not sure which Cloudflare feature to use?
Open a Discussion describing what you want to build. The community can help suggest the right Cloudflare features.
Can I use multiple Cloudflare features in one experiment?
Can I use multiple Cloudflare features in one experiment?
Yes, but the experiment should have a single clear purpose. For example,
link-shortener uses both D1 and KV, but its purpose is clear: shorten URLs.Do I need to create database migrations?
Do I need to create database migrations?
Include the SQL schema in your README.md so users can set up the database. For D1, users will run
wrangler d1 execute with your schema.How do I handle secrets?
How do I handle secrets?
Use Cloudflare secrets via
wrangler secret put SECRET_NAME. Document required secrets in your README.md. Never commit actual secret values.Next Steps
- Review the Code Standards for implementation details
- Check the Contributing Guide for PR guidelines
- Browse existing experiments for inspiration
- Open an experiment idea issue to get started