Replace the in-browser search with the server's: GET /api/stalls?q=… searches names and blurbs. It has to feel instant, show the right results for what's in the box, and live in the URL so a search can be shared and the Back button works. ★★☆
“Somebody said there's a stall with pineapple. Which one was it?”
You'll demo (next class): type "pineapple" quickly: one request after you stop, and Taco Bike. Copy the URL into a new tab: same search, same result. Type, then press Back: the previous search comes back.
Four things, on top of your connected market. They count when they work with chaos on (control page).
GET /api/stalls?q=, built with URLSearchParams.AbortError never reaches the user or the console.What has to work for the demo next class, not how. The core above is part of it.
GET /api/stalls?q= built with URLSearchParams, combined with the tag filter (?tag=food&q=…).AbortController).?q=pineapple&tag=food), and the page starts from them on load.AbortError is never shown to the user and never reaches the console.New tool: history.replaceState / pushState and the popstate event: change the URL without reloading.
| Method | Path | Answers |
|---|---|---|
GET | /api/stalls?q=&tag=&sort= | 200 · array, X-Total-Count · 400 for an unknown tag |
The server answers short queries slowly and long ones fast (more matches to rank): q=t takes about 0.7 s, q=pineapple about 0.1 s. Out-of-order responses are guaranteed.
q=./?q=%3Cb%3E (a query with HTML in it).innerHTML.Network panel first: is the request sent, with what, and what came back? Then a hint.
Debounce and abort solve two different problems. Which one does each solve, and which one makes the result correct?
replaceState or pushState: should every keystroke be a Back step?
On load, the URL has a query. What runs first: reading it, or the first render?
This brief assumes Connect the market is done: api.js works, the stalls come from the API, loading and errors are handled. Then: Typing sends GET /api/stalls?q=…; with fast typing, earlier ones show (canceled) in the Network panel.