Build a guestbook · Exercise 01
Build the UI
Build your guestbook's form and list, with a small API that keeps entries in memory for now.
Paste this into your agent
Copied! Now paste it into your agent. No agent yet? Here's how to get one.
Build the UI
Every guestbook has the same two parts: a form where visitors leave their name and a message, and a list of what people have written. In this exercise you’ll build both, plus a small API between them.
What you’ll build
A guestbook on your site, in the style you described, backed by two routes: POST /api/entries to sign it and GET /api/entries to read it. For now the entries live in your Worker’s memory, which works on your machine, until it doesn’t.
Text, not HTML
Anyone can type anything into your form, including HTML or a <script> tag. Your page puts each entry on the screen as plain text (with textContent, or your framework’s normal escaping), so whatever someone types shows up as text and never runs in another visitor’s browser.
Why the entries disappear
Restart the dev server and the entries are gone. A Worker isn’t a server that stays running: Cloudflare starts copies of it wherever requests arrive, runs as many as it needs, and stops them when they’re idle. A variable lives in one copy, for as long as that copy runs. To keep entries, you need storage that every copy can reach, and that’s the next exercise.
Prerequisites
Your agent can help you with these.
- Node.js installed.
- A free Cloudflare account.
- The
cfCLI logged in to your Cloudflare account (cf auth whoami). - A site or app to add the guestbook to, or nothing: your agent can start a new Worker for it.