Forms & Mutations

Overview


In Parts 2 and 3, we developed a browser interface that reads API data and server operations that validate and store changes. We will now connect those operations to forms. We will first construct an HTTP mutation explicitly, then refactor its request construction to a typed Hono client while keeping the working behavior. We will also show pending feedback, preserve input after rejection, and recover when a response leaves the server outcome uncertain.

This part uses a new practice application (practice-typed-http/) for chapter examples. After a local form preview, we will develop the same notes workflow through validation, typed requests, debugging, and testing. Continue the marketplace project in the separate marketplace repository (marketplace/), applying these ideas to seller and buyer interactions.

Part structure

Typed HTTP APIs walking skeleton

Download the typed HTTP APIs walking skeleton, extract it to a folder called practice-typed-http, and open that folder in your editor. Keep your earlier practice/ directory. The distinct folder name gives the new application its own Compose project and database volume.

Stop the earlier practice application’s running services with docker compose down from that application’s folder. Stop the marketplace’s development services too if they are using ports 5173 and 8000. Then, from practice-typed-http/, run:

Terminal window
docker compose up --build

Open http://localhost:5173. The home page links to /examples/fetch and /examples/typed: complete forms that create and read notes through the same API and PostgreSQL database, using explicit requests and a typed client respectively. Create a note and reload to check that it was stored. Keep these examples for comparison, and build your chapter examples on /lab (client/src/routes/lab/+page.svelte).

To start with an empty practice database, first check that your terminal is in practice-typed-http/, then run docker compose down --volumes followed by docker compose up --build. Removing this project’s volume deletes its practice notes; startup reapplies the migration. Use the separate test-project commands for test cleanup.