Skip to main content
This guide walks you through the process of adding a new experiment to the Cloudflare Experiments repository.

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

1

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.)
Wait for maintainer feedback before proceeding.
2

Create the experiment directory

Create a new directory under experiments/<name>/:
Use kebab-case for the experiment name (e.g. is-it-down, link-shortener).
3

Set up the project structure

Create the standard directory structure:
Your directory should look like:
4

Initialize package.json

Create a package.json with the required dependencies:
Then install dependencies:
5

Create wrangler.toml

Configure your Worker with wrangler.toml:
Or use wrangler.json if you prefer JSON format.
6

Set up TypeScript configuration

Create tsconfig.json:
7

Implement the Worker

Follow the code standards to implement your Worker:Create src/types/env.d.ts:
Create src/utils/response.ts:
Create src/lib/url.ts (if handling URL params):
Create your route handlers in src/routes/:
Create src/index.ts:
8

Test locally

Run your experiment locally:
Test your endpoints:
Verify:
  • All routes work as expected
  • Error handling works correctly
  • TypeScript has no errors
9

Create README.md

Document your experiment with a comprehensive README:
Response
Errors
  • 400 - Invalid parameter

Run locally

Deploy

Deploy to Cloudflare Workers

Cloudflare features used

  • Workers
  • List relevant features
10

Submit a pull request

Create a PR with:
  • Clear title: “Add [experiment-name] experiment”
  • Description linking to the experiment idea issue
  • Screenshots or examples of the API in action (if applicable)
  • Confirmation that npx wrangler deploy works
Fill in the PR template with all required information.

Common Patterns and Examples

Using Reference Experiments

You can use existing experiments as references:
Reference: whereami or is-it-downThese experiments:
  • Don’t use persistent storage
  • Have simple route handlers
  • Focus on edge networking
Good for: Simple APIs, URL validators, fetch-based tools
Reference: link-shortenerThis experiment:
  • Uses D1 for primary storage
  • Uses KV for read cache
  • Handles database errors gracefully
  • Implements retry logic for unique constraints
Good for: CRUD operations, data persistence, caching patterns
Reference: ai-website-summary or github-repo-explainerThese experiments:
  • Use Workers AI binding
  • Handle streaming responses
  • Process external content
Good for: AI-powered tools, content analysis, summarization
Reference: screenshot-apiThis experiment:
  • Uses Browser Rendering API
  • Handles binary responses (images)
  • Implements proper timeouts
Good for: Screenshot tools, browser automation, PDF generation

Error Handling Patterns

Handling fetch errors:
Handling JSON parsing errors:
Handling database constraint errors:

Deployment Checklist

Before submitting your PR, verify:
  • npm run dev works locally
  • npx wrangler deploy deploys successfully
  • All endpoints return proper JSON responses
  • Error codes are descriptive (e.g. INVALID_URL, not ERROR)
  • Global error handler returns consistent 500 responses
  • README.md documents all API endpoints
  • Bindings are declared in both wrangler.toml and src/types/env.d.ts
  • TypeScript strict mode passes with no errors
  • No any types in the code
  • Added experiment to root README.md table

Getting Help

Open a Discussion describing what you want to build. The community can help suggest the right Cloudflare features.
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.
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.
Use Cloudflare secrets via wrangler secret put SECRET_NAME. Document required secrets in your README.md. Never commit actual secret values.

Next Steps

Thank you for contributing to Cloudflare Experiments!