A page for the market's organisers and vendors: add a stall, edit it, mark it sold out, remove it. The routes that change stalls need a token in an Authorization header, and the server says no in five different ways. The public page shows the changes on its next load. ★★★
“Churros just restocked. Can somebody take the sold-out sign off?”
You'll demo (next class): with the admin token, add "Crêpe Escape", mark Mezcal Moon as no longer sold out, delete a stall. Then each error: no token and a made-up token (401), Taco Bike's vendor token on Mezcal Moon (403), a duplicate name (409), a price of -3 (422).
Four things, on top of your connected market. They count when they work with chaos on (control page).
starter/admin.html and js/admin.js are there as a starter (a token field, an empty table): fill the table from GET /api/stalls, with loading and error.sessionStorage), sent as Authorization: Bearer … on every change.PATCH { soldOut }, the row redrawn from the response.What has to work for the demo next class, not how. The core above is part of it.
starter/admin.html (open localhost:8080/admin.html), with its own module js/admin.js.sessionStorage and sent as Authorization: Bearer ….POST a stall, PATCH fields (sold out is a checkbox), DELETE with a confirmation.New tool: sessionStorage: like localStorage, forgotten when the tab closes.
| Method | Path | Answers |
|---|---|---|
POST | /api/stalls | 201 + Location · 401 · 403 (vendor token) · 409 · 422 { fields } |
PATCH | /api/stalls/:id | 200 · 401 · 403 (another vendor's stall) · 404 · 422 |
DELETE | /api/stalls/:id | 204 · 401 · 403 · 404 |
GET | /api/stalls | 200 · no token needed |
Tokens: harbour-admin-2026 may do everything; vendor-<stall id> (e.g. vendor-taco-bike) may only PATCH its own stall. They're printed here because this is a course server; a real token comes from a login and never appears in your code.
Network panel first: is the request sent, with what, and what came back? Then a hint.
Every admin request needs the same header. How many places in your code should know how to add it?
PATCH: what do you send, the whole stall or only what changed? What does the API's contract say?
A 401 and a 403 both mean "no". After which one should the user type a different token, and after which one should they ask someone else?
"4": 422.This brief assumes Connect the market is done: api.js works, the stalls come from the API, loading and errors are handled. Then: PATCH /api/stalls/mezcal with { "soldOut": false } answers 401 without the header and 200 with it.