Course lesson 06 · Building on Cloudflare Workers
Binding resources to your Worker
Bindings connect a Worker to a Cloudflare resource through its runtime environment. The lesson demonstrates the recurring pattern with KV: create a namespace, declare it in Wrangler, regenerate types, then read and write through the binding. The same discovery process extends to other Cloudflare products, reducing the amount of connection setup repeated in application code.
Primary source: course video 06 · Supplied English subtitles · 00:06:59.
Understand the idea
- The resource exists independently of the Worker; a named binding gives that Worker access to it.
- The binding name is the property your code uses, whereas the resource ID identifies the configured Cloudflare resource.
- Wrangler’s configuration schema and generated environment types help discover and check the available fields and methods.
- Local development normally uses simulated resource state under .wrangler; the course’s experimental remote option selects the hosted resource instead.
- KV, D1, R2, Queues, AI, and other products provide distinct capabilities while following a similar resource-binding workflow.
What the course does
- Create the demonstration KV namespace in the Cloudflare dashboard.
- Add its namespace ID and an application-facing binding name to the Worker’s Wrangler configuration.
- Run the script that invokes Wrangler type generation so the binding becomes visible to TypeScript.
- Add one route that stores a supplied ID under a fixed key and another route that reads that key.
- Run locally, write two different IDs in sequence, and confirm the read route reflects the persisted state in the demonstration environment.
Watch for
- The fixed-key save/read routes are explicitly a teaching example, not the final Smart Links cache design.
- Experimental remote configuration and product/free-tier details are recording-specific.
- Added advice: know whether a development command targets local state or a hosted resource before using it with meaningful data.
Recall before revealing
What is the difference between a KV resource ID and its binding name?
Reveal the explanation
The ID selects the namespace in Cloudflare; the binding name is the environment property through which this Worker accesses it.
Try it
Reproduce the demonstration with an isolated test KV namespace and explain where the saved ID lives during your chosen development mode.
Check your result
The read route retrieves the saved value, and you can identify the configuration, generated type, and method call involved.
Practice prompts and answer checks are added teaching material. Answer from memory first, then compare and explain any difference.
Rewatch only what you need
Open this lesson in your original course library and seek to the times below. Videos are not hosted on this site.
- 00:01:00 — Resources and bindings across products
- 00:02:00 — Create and bind a KV namespace
- 00:03:00 — Local state versus remote bindings
- 00:04:00 — Generate types and implement KV routes
Companion primary documentation: Cloudflare resource bindings. For recorded API names, commands, limits, and prices, check the version you use.