🌐Fetch API
Also known as fetch(), JavaScript Fetch, window.fetch
The way code in a web page asks a server for data.
Think of it like
Think of it like sending a friend to the shop. You keep playing, and they come back with the bag.
Example
Lucy's weather page calls fetch("/api/weather"). Soon it shows 18°C, and the page does not reload.
Why it matters
Most modern pages load data this way after they open. It is why a feed can update without a full reload.
Definition
Example code
javascript
const res = await fetch("/api/weather");
if (!res.ok) throw new Error(res.status);
const data = await res.json();Common mistake
Key takeaways
- 1Built in. No library is needed in the browser.
- 2Works with promises. The page keeps running while it waits.
- 3Check the status. An error page still counts as an answer.