Home › Web › APIs
Web

APIs

An API is how one program talks to another. A web API lets your code ask a server for data or tell it to do something, usually over HTTP with JSON.

Endpoints

An API exposes URLs called endpoints, each for a particular thing. You send a request to one and get a response back.

GET  /api/users        list users
GET  /api/users/7      one user
POST /api/users        create a user

Requests and responses

You send a method, a path, maybe headers and a JSON body. You get back a status code and usually JSON.

const res = await fetch('/api/users/7');
const user = await res.json();

Authentication

Most APIs need to know who you are. You send a key or token, often in an Authorization header, so the server can check you are allowed.

Keep reading: TLS / HTTPS  ·  SQL  ·  Cookies