Vibe Coding: build real apps with AI · Episode 14. Every agent run below is real: Claude Code 2.1.319 (model claude-sonnet-5-5) in print mode (claude -p), on 7 November 2026, in /home/ravi/projects/tasks-api (a Git repository), with Node.js v22.23.4 and Express 5.3.0 (npm view express version on 7 Nov 2026). Every curl result and browser result was run against that server. Replies are quoted exactly, shortened where marked ....
The problem: the phone shows no tasks
Ravi's to-do app saves tasks in localStorage (Episode 10). He added three tasks on his laptop, then opened the same page on his phone: "No tasks yet." We tested it with two separate Chromium browsers (a laptop window and an emulated Pixel 7 phone): on the phone, localStorage.getItem('tasks') returned null.
Why: localStorage lives inside one browser on one device, like a diary in your own bag. Another device can't read it.
The fix we invent: keep the list in one place that every device can ask. That place is a server.
Client and server (a restaurant)
| A restaurant | A web app |
|---|---|
| the customer asks for food | the client (browser, phone app) asks |
| the kitchen has the food and does the work | the server: a program that waits for requests and answers them |
| the order slip: "2 dosas, table 4" | the request: what the client wants |
| the plate that comes back (or "sold out") | the response: data, or an error |
One kitchen serves many tables; one server serves all of Ravi's devices.
The rules for requests and responses on the web are HTTP (Hypertext Transfer Protocol).
Client (phone) ── GET /tasks ──────────────────▶ Server
reads its list
Client ◀── 200 OK + the tasks as JSON ── Server
What's inside a request and a response
| Request part | Meaning | Example |
|---|---|---|
| method | what to do | GET, POST, PUT, PATCH, DELETE |
| path | which thing | /tasks, /tasks/2 |
| headers | labels on the parcel | Content-Type: application/json |
| body | the data itself (if any) | {"title":"Buy milk"} |
| Response part | Meaning | Example |
|---|---|---|
| status code | a number saying how it went | 201 Created |
| headers | labels | Location: /tasks/1 |
| body | the data | {"id":1,"title":"Buy milk","done":false} |
One prompt: the agent builds the backend
claude -p "Build a small backend for my to-do app in this folder, with Node.js and Express. It keeps a list of tasks
(each has an id, a title and done true/false) and has REST endpoints to list all tasks, get one task, add a task, update
a task and delete a task. Use JSON. Return the right HTTP status codes. Keep it in one file, server.js, plain
JavaScript. Then start the server and test every endpoint with curl." --allowedTools Read Write Edit Glob
"Bash(npm:*)" "Bash(node:*)" "Bash(curl:*)" "Bash(ls:*)"
Real log (shortened):
Bash npm init -y && npm install express → found 0 vulnerabilities
Write server.js
Edit "The PATCH re-dispatch I wrote is hacky, so I'll replace it"
Bash nohup node server.js > ... &
→ "uses the `&` background operator ... Approve only if you trust it."
Its reply: "I wrote server.js, but I haven't started the server or run the curl tests yet. The permission system blocked my attempts to start it in the background and I haven't worked around that."
That honesty is good. "Not tested" means you test it.
Express is a small, free Node.js library for writing web servers.
The shape of an Express server (the AI's real code)
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json());
// In-memory store
let tasks = [];
let nextId = 1;
// List all tasks
app.get('/tasks', (req, res) => {
res.status(200).json(tasks);
});
...
app.listen(PORT, () => {
console.log(`Tasks API listening on http://localhost:${PORT}`);
});
app.use(express.json())reads JSON request bodies (but only when the request'sContent-Typeis JSON: see the bug below).app.get('/tasks', ...): when aGETrequest for/tasksarrives, run this function.reqis the request,resthe response we send.app.listen(PORT, ...)starts waiting for requests. A server never finishes on its own; it keeps listening until you press Ctrl+C.- The tasks are in a normal array, in memory. Keep that in mind.
ravi@laptop:~/projects/tasks-api$ node server.js
Tasks API listening on http://localhost:3000
The browser is a client too
http://localhost:3000/ (404 Not Found)
{"error":"Route not found"}
http://localhost:3000/tasks (200 OK)
[]
The AI added a catch-all for unknown paths, so / gives 404. /tasks gives an empty list. An address bar can only send GET requests; to add a task we need another client.
Endpoints, APIs and REST (a menu)
An endpoint is one thing a server offers: a method + a path, like one line on a menu. The whole menu is the API (application programming interface): the list of things a program lets other programs ask for.
| Method | Path | Does | CRUD |
|---|---|---|---|
| GET | /tasks |
list all tasks | Read |
| GET | /tasks/:id |
get one task | Read |
| POST | /tasks |
add a task | Create |
| PUT (and PATCH) | /tasks/:id |
update a task | Update |
| DELETE | /tasks/:id |
delete a task | Delete |
:id is a route parameter: any value can go there (/tasks/2, /tasks/99), and Express gives it to you as req.params.id.
REST (Representational State Transfer): MDN calls it "a group of software architecture design constraints". In everyday use, a REST API means: things (nouns) in paths, actions (verbs) in methods. CRUD = Create, Read, Update, Delete: what almost every app does to its data.
Testing with curl
curl is a free command-line tool that sends HTTP requests (check you have it: curl --version).
| Option | Means |
|---|---|
-i |
show the response headers too |
-X POST |
use this method |
-H "Name: value" |
add a header |
-d '...' |
send this data as the body |
$ curl -i localhost:3000/tasks
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 2
Date: Sat, 07 Nov 2026 16:15:46 GMT
Connection: keep-alive
[]
The obvious way to add a task fails
$ curl -i -X POST localhost:3000/tasks -d '{"title":"Buy milk"}'
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{"error":"title is required and must be a non-empty string"}
We sent a title. Why "required"?
- curl's manual:
-d"makes curl pass the data to the server using the content-type application/x-www-form-urlencoded" (an old-style HTML form), not JSON. - Express's docs:
express.json()"only looks at requests where the Content-Type header matches"application/json, andreq.bodyisundefinedif "the Content-Type was not matched". - So the body was never read. The server was right; the request was wrong.
Fix: add the label.
$ curl -i -X POST localhost:3000/tasks -H "Content-Type: application/json" -d '{"title":"Buy milk"}'
HTTP/1.1 201 Created
Location: /tasks/1
Content-Type: application/json; charset=utf-8
{"id":1,"title":"Buy milk","done":false}
201 Created: a new thing was made. Location says where it lives.
The POST endpoint (the AI's real code)
app.post('/tasks', (req, res) => {
const { title, done } = req.body || {};
if (typeof title !== 'string' || title.trim() === '') {
return res.status(400).json({ error: 'title is required and must be a non-empty string' });
}
if (done !== undefined && typeof done !== 'boolean') {
return res.status(400).json({ error: 'done must be true or false' });
}
const task = { id: nextId++, title: title.trim(), done: done === true };
tasks.push(task);
res.status(201).location(`/tasks/${task.id}`).json(task);
});
Checking input before trusting it is validation. The AI did it well here.
Status codes (a courier tracker)
MDN groups status codes by their first digit:
| Class | Meaning | Like a courier tracker | Examples |
|---|---|---|---|
| 1xx | informational | ||
| 2xx | success | "Delivered" | 200 OK, 201 Created, 204 No Content |
| 3xx | redirection | ||
| 4xx | client error: fix your request | "Wrong address" | 400 Bad Request, 404 Not Found, 413 Content Too Large |
| 5xx | server error: fix the server | "Our van broke down" | 500 Internal Server Error |
More real runs (after adding "Pay electricity bill" and "Call Asha about rent"):
$ curl -i localhost:3000/tasks/2
HTTP/1.1 200 OK
{"id":2,"title":"Pay electricity bill","done":false}
$ curl -i localhost:3000/tasks/99
HTTP/1.1 404 Not Found
{"error":"Task not found"}
$ curl -i -X PUT localhost:3000/tasks/1 -H "Content-Type: application/json" -d '{"done":true}'
HTTP/1.1 200 OK
{"id":1,"title":"Buy milk","done":true}
$ curl -i -X DELETE localhost:3000/tasks/3
HTTP/1.1 204 No Content
$ curl -i -X DELETE localhost:3000/tasks/3
HTTP/1.1 404 Not Found
{"error":"Task not found"}
PUT vs PATCH: notice what the AI adds
// Update a task (partial update: send title and/or done)
const updateTask = (req, res) => { ... };
app.put('/tasks/:id', updateTask);
app.patch('/tasks/:id', updateTask);
We never asked for PATCH, and the agent made PUT and PATCH do the same partial update. MDN: "The PATCH HTTP method applies partial modifications to a resource", whereas "PUT represents a complete replacement of the resource." PUT is also idempotent: sending the same request once or ten times leaves the server in the same state.
For this app it works fine, but other programmers reading PUT expect a full replace. When an AI adds something you didn't ask for: notice it, then decide (ask it to explain, or to remove it).
The bug the AI missed: a client's mistake answered with 500
Try to break it:
$ curl -i -X POST localhost:3000/tasks -H "Content-Type: application/json" -d '{"title": "x",}'
HTTP/1.1 400 Bad Request
{"error":"Invalid JSON body"}
$ curl -i -X POST localhost:3000/tasks -H "Content-Type: application/json" --data @big.json
HTTP/1.1 500 Internal Server Error # big.json = one title of 200,000 letters
{"error":"Internal server error"}
The server's terminal:
PayloadTooLargeError: request entity too large
at readStream (.../raw-body/index.js:163:17)
...
expected: 200013, length: 200013, limit: 102400, type: 'entity.too.large'
express.json() has a default limit of "100kb" (102,400 bytes). Sending too much is the client's mistake (a 4xx), but the server answered 500 ("my fault"). That's wrong, and it hides real server failures among fake ones.
Why (the AI's error handler):
// Error handler (e.g. malformed JSON)
app.use((err, req, res, next) => {
if (err.type === 'entity.parse.failed') {
return res.status(400).json({ error: 'Invalid JSON body' });
}
console.error(err);
res.status(500).json({ error: 'Internal server error' });
});
An error handler is a function Express calls when something goes wrong (it takes four inputs, err first). It knew one error; everything else became 500, even errors that already carried a correct code.
Fix prompt (after a commit, so it can be undone):
claude -p "Bug: when I POST a task whose JSON body is bigger than 100 kB, the server answers "HTTP/1.1 500 Internal
Server Error" {"error":"Internal server error"} and the log shows "PayloadTooLargeError: request entity too large"
with type: 'entity.too.large'. That is the client's fault, not the server's, so it should not be a 500. Fix the error
handler so client errors keep their real status code. Change only what's needed. I'll start the server and test it
myself." --allowedTools Read Edit Glob
The agent added four lines:
const status = err.status || err.statusCode;
if (status >= 400 && status < 500) {
return res.status(status).json({ error: err.message });
}
and said: "An oversized body should now return 413 ... I haven't run it, since you said you'd test." Re-test:
$ curl ... --data @big.json → HTTP/1.1 413 Payload Too Large {"error":"request entity too large"}
$ curl ... -d '{"title": "x",}' → HTTP/1.1 400 Bad Request {"error":"Invalid JSON body"}
$ curl ... -d '{"title":"Buy milk"}' → HTTP/1.1 201 Created {"id":1,"title":"Buy milk","done":false}
MDN, 413: "the request entity was larger than limits defined by server."
The same idea in Python: FastAPI
FastAPI is a popular Python library for building APIs. Real run (FastAPI 0.162.2, uvicorn 0.54.0):
from fastapi import FastAPI
app = FastAPI()
tasks = [{"id": 1, "title": "Buy milk", "done": False}]
@app.get("/tasks")
def list_tasks():
return tasks
$ uvicorn main:app --port 8000
$ curl -i localhost:8000/tasks
HTTP/1.1 200 OK
[{"id":1,"title":"Buy milk","done":false}]
@app.get("/tasks") is a decorator: it registers the function for GET /tasks. Returning a list makes FastAPI send JSON. Same ideas, different language.
The next problem: restart = empty
$ curl localhost:3000/tasks
[{"id":1,"title":"Buy milk","done":false},{"id":2,"title":"Pay electricity bill","done":false},
{"id":3,"title":"Call Asha about rent","done":false}]
# Ctrl+C, then start it again
$ node server.js
Tasks API listening on http://localhost:3000
$ curl localhost:3000/tasks
[]
The array lived in the server's memory, which is wiped when the program stops. Episode 15 adds a database.
$ git log --oneline
02e1240 Keep 4xx status for client errors (413 for big bodies)
d470b28 Tasks API with Express (AI)
Common mistakes (real)
| Mistake | What you see | Why | Fix |
|---|---|---|---|
curl -X POST ... -d '{"title":...}' |
400 "title is required" |
the body is labelled as a form, not JSON | -H "Content-Type: application/json" |
| Error handler turns everything into 500 | 500 + PayloadTooLargeError |
client errors lose their real code | keep err.status for 4xx |
| Data in a plain array | [] after a restart |
memory is wiped when the program stops | a database (Episode 15) |
| "The AI said it works" | "I haven't ... run the curl tests" | untested endpoints | test every endpoint, then try to break it |
| Treating PUT and PATCH the same without noticing | surprising behaviour for other clients | PUT means full replacement | decide on purpose; document it |
Mini project
Ask an AI for a small Express API for a cricket scoreboard: GET /matches, POST /matches (team names required), PATCH /matches/:id (runs and wickets), DELETE /matches/:id. Then test every endpoint with curl -i, send a body without the JSON header, send broken JSON, send a 200 kB body, and ask for an id that doesn't exist. Write down every status code you get.
What a good outcome looks like
201 with a Location header for a new match; 400 for missing team names or broken JSON; 413 for the huge body (not 500); 404 for an unknown id; 204 for a delete; 200 for reads and updates. Negative runs or wickets above 10 are rejected with 400.
Practice questions
- What's the difference between a client and a server?
Answer
The client asks (browser, phone app, curl); the server is a program that waits for requests and answers them.
- Name the four parts of an HTTP request.
Answer
Method, path, headers, body.
- Which status code fits: a new note was created? The id doesn't exist? The JSON is broken? The database crashed?
Answer
201 Created; 404 Not Found; 400 Bad Request; 500 Internal Server Error.
- Why did
curl -X POST ... -d '{"title":"Buy milk"}'get "title is required"?
Answer
Without -H "Content-Type: application/json", curl labels the body as form data, so express.json() doesn't parse it and req.body is undefined.
- Why do the tasks disappear when the server restarts?
Answer
They're stored in an array in memory, which is wiped when the program stops.
- What's the difference between PUT and PATCH?
Answer
PUT replaces the whole resource (and is idempotent); PATCH applies a partial change.
Quiz
$ curl -i -X POST localhost:3000/tasks \
-H "Content-Type: application/json" \
-d '{"title":" "}'
With our server, what comes back? A) 200 OK B) 201 Created C) 400 Bad Request D) 500 Internal Server Error
Answer
C) 400: title.trim() === '', so the server rejects it as the client's mistake.
Interview questions
- Walk through what happens when a browser requests
GET /tasksfrom a server. - What makes an API "RESTful"? Give an example of a non-RESTful path.
- Explain 4xx vs 5xx with an example of each.
- What is idempotency? Which HTTP methods are idempotent?
- Why should a server validate input even if the front end already does?
- How would you test an API you didn't write?
Glossary
| Term | Meaning (plain words) | Example |
|---|---|---|
| Backend | the part of an app that runs on a server: data and rules | our tasks API |
| Front end | the part the user sees and clicks | the to-do page |
| Client | the program that asks | browser, phone, curl |
| Server | a program that waits for requests and answers them | node server.js |
| Request | what the client sends: method, path, headers, body | POST /tasks |
| Response | what comes back: status code, headers, body | 201 Created |
| HTTP | the rules for requests and responses on the web | HTTP/1.1 200 OK |
| Method | what to do with a thing | GET, POST, PUT, PATCH, DELETE |
| GET | read something | GET /tasks |
| POST | create something | POST /tasks |
| PUT | replace something | PUT /tasks/1 |
| PATCH | change part of something | PATCH /tasks/1 |
| DELETE | remove something | DELETE /tasks/3 |
| Path | which thing | /tasks/2 |
| Header | a label on a request or response | Content-Type: application/json |
| Body | the data inside a request or response | {"title":"Buy milk"} |
| Content-Type | the header saying what format the body is | application/json |
| Status code | a number saying how it went | 404 |
| Endpoint | one method + path a server offers | GET /tasks/:id |
| API | the list of endpoints programs can use | our five endpoints |
| REST | a style: nouns in paths, verbs in methods | DELETE /tasks/3 |
| CRUD | Create, Read, Update, Delete | POST, GET, PUT, DELETE |
| Route parameter | a placeholder in a path | :id → req.params.id |
| Express | a small Node.js library for web servers | app.get(...) |
| Middleware | a function that runs on requests before your route | express.json() |
express.json() |
middleware that parses JSON bodies | fills req.body |
| Error handler | a function Express calls when something fails | (err, req, res, next) |
| localhost | this computer | localhost:3000 |
| Port | a numbered door for one service | 3000 |
| curl | a command-line HTTP client | curl -i localhost:3000/tasks |
| JSON | a text format for data | [{"id":1}] |
| Validation | checking input before trusting it | empty title → 400 |
| Idempotent | doing it once or many times has the same effect | PUT, DELETE |
| In memory | stored only while the program runs | let tasks = [] |
| FastAPI | a Python library for APIs | @app.get("/tasks") |
| Decorator | a Python @ line that wraps a function |
@app.get |
| uvicorn | the program that runs a FastAPI app | uvicorn main:app |
Summary
localStorage lives in one browser, so Ravi's phone saw no tasks; the fix is a server every device can ask. A client sends an HTTP request (method, path, headers, body); the server sends a response (status code, headers, body). An endpoint is a method + path; the set of endpoints is the API; REST puts nouns in paths and verbs in methods, giving CRUD. The agent wrote a good Express server but couldn't start it and said so. We tested it with the browser and curl, hit a 400 caused by a missing Content-Type header, learned the status-code families, noticed that PUT and PATCH were made identical, and found a real bug: a too-large body answered with 500 instead of 413. One precise prompt fixed it, and a re-test proved it. Finally, a restart wiped every task: memory isn't storage. Next: a database.