Workers · Exercise 02

Add a binding

Create a Workers KV namespace, bind it to the Worker you already deployed, and read and write a value through it to prove the binding actually persists data.

Add a binding

This exercise extends the Worker you deployed in Deploy a Worker. You’ll create a Workers KV namespace, bind it to that Worker, and read and write values through it: the first taste of what a Cloudflare binding is and why it matters. Your agent does the typing; you make the calls.

What you’ll build

The same Worker, now with a KV binding on env. Its homepage still shows the response from the first exercise. You’ll write a value (e.g. via a query string) and, in a separate request, read it back from the public URL. Getting the same value back proves the binding actually persists data, not that a single request just echoed something.

You name the namespace and choose what to store. Before anything ships, your agent shows you the one line in cloudflare.config.ts that declares the binding, and you’ll predict what happens when you read a key nobody wrote. Then you’ll store and overwrite a few values of your own.

Out of scope: multiple namespaces, TTLs, R2/D1, and other storage.

Prerequisites

Your agent can help you with these.

  • You’ve completed Deploy a Worker and still have that project on disk.
  • The cf CLI authenticated against your Cloudflare account (cf auth whoami).