Track 06 · Lesson 1 of 8APIs and servers
What an API is
Lesson 1 of 8· 7 min
An API is a promise between two programs: send me this, and I’ll send you that. Your website, your mobile app and a partner’s system can all use the same API, because they only depend on the promise, not on how it’s kept.
Order a pizza through an API
Try every endpoint, then break the request
Requests and responses, again#
A web API is HTTP with JSON instead of HTML. Each endpoint is a method plus a path, like POST /orders. The request may carry a JSON body; the response carries a status code and usually JSON back. Everything you learned about methods, headers and status codes applies unchanged.
Errors are part of the promise#
A good API tells the caller exactly what went wrong, in a predictable shape. 400 means it couldn’t read the request at all; 422 means it read it but the values break the rules, and it lists which ones; 404 means that thing doesn’t exist. Clients can only handle errors they can recognise.
Never trust the caller#
The API is the real gatekeeper. Anyone can call it directly with curl, skipping your website’s form entirely, so every rule must be checked here: types, ranges, who’s allowed to do what. The form’s checks are only there to help people.
Check yourself