0
APIs & Async · Introduction to APIs & Async
New technique
Talking to distant forges
My forge can't mine its own ore. We send a runner to the mines, and a cart comes back. That's an API call!
Most data doesn't live in the page itself. Your messages, a shop's stock: it sits on a server, and the page has to ask for it.
An API (Application Programming Interface) is the contract for how two programs talk. On the web, your page is the client. It sends an HTTP request to an endpoint: a URL on the server that stands for one kind of data, like /swords/42 for sword number 42.
The server sends back a response: a status saying how it went, plus the data, usually as JSON text.
GET https://api.example.com/swords/42
→ 200 OK
{ "id": 42, "name": "Ember Edge", "metal": "steel" }