What is a REST API?
A REST API lets your app get or change data on a server by sending requests to web addresses, like /users/42 for user number 42. It’s the most popular style of API on the web. Each kind of thing your app cares about, like users or orders, gets its own address. Your app sends an HTTP request to that address and the server sends back what you asked for.
Here’s what a REST API might look like for an app whose backend keeps its users in a database:
GET /users/42 fetch user 42
POST /users create a new user
PUT /users/42 replace user 42
DELETE /users/42 remove user 42
A GET request reads data and a POST request creates something. A PUT request replaces an existing record and a DELETE request removes it. The server answers with JSON and an HTTP status code like 200 when things worked or 404 when user 42 doesn’t exist. You can call a REST API from JavaScript with fetch or from a terminal with curl. Lots of companies also wrap their REST API in an SDK so you don’t have to build the requests yourself.
REST stands for Representational State Transfer and comes from Roy Fielding’s 2000 PhD dissertation at UC Irvine. Fielding was also one of the main authors of the HTTP spec, so REST fits naturally with the way the web already works. One big idea is that REST is stateless, meaning every request carries everything the server needs. The server doesn’t have to remember anything from earlier requests, so a login token like a JWT gets sent along with every request.
I remember when REST APIs first came out and the whole idea felt very academic because everyone kept referencing Fielding’s paper. REST has been the standard for so long that I don’t think about it anymore. There are plenty of times where plain REST isn’t enough. GraphQL is a popular alternative with a lot of benefits there because the client can ask for exactly the fields it wants from a single endpoint. REST is still the default though because it has a ton of tooling around it.