What is a REST API? REST API Explained
Blog / What is a REST API? REST API Explained
What is a REST API? And why is it the way almost every web and mobile app talks to its backend?
The Problem: Every API Invents Its Own Shape
Without a shared style, every API invents its own shape. Developers name operations their own way, usually as verbs in the URL, like POST /createUser, GET /getUser?id=42 or GET /deleteOrder.Every new API has to be learned from scratch. Using a GET request to delete something is also surprising and unsafe.This is where REST comes in. It provides one uniform way to design an API on top of HTTP.Resources and URIs
In REST, everything is a resource, like a user or an order. Every resource is identified by a URI.You should use plural nouns and never verbs, for example /users or /users/42. You can show relationships by nesting them, like /users/42/orders.The URI names the thing, and the HTTP method says what to do with it.HTTP Methods and CRUD
Standard HTTP methods map cleanly to create, read, update and delete actions on the same /users URI.- GET reads data.
- POST creates new data.
- PUT replaces the whole resource entirely.
- PATCH updates only part of the resource.
- DELETE removes it.
A Request End to End
Let's walk through a client creating an order. The client sends a request with the POST method and the /orders URI.The request includes headers for Content-Type: application/json and an Authorization token, along with a small JSON body.The server responds with 201 Created, a Location header pointing at the new order, and the order itself as JSON.
Status Codes
The status code tells the client what happened before it reads the body.- Codes starting with 2 indicate success, like 200 OK, 201 Created and 204 No Content.
- Codes starting with 4 mean the client made a mistake, like 400 Bad Request, 401 Unauthorized, 403 Forbidden and 404 Not Found.
- Codes starting with 5 mean the server failed, like 500 Internal Server Error.

Stateless
The server keeps no session for the client between requests. Every request carries everything needed to handle it, including the authentication token.Any server behind a load balancer can handle any request, which makes REST APIs very easy to scale horizontally.Tokens like JWTs are a topic of their own, and we have another video explaining them.Safe vs Idempotent Methods
Safe means the request does not change anything on the server. GET and HEAD are safe methods.Idempotent means sending the request once or many times leaves the server in the exact same state. GET, PUT and DELETE are idempotent.POST is not idempotent. If a network timeout makes the client retry a payment, the user can be charged twice.
What Makes an API RESTful
REST is an architectural style from Roy Fielding's 2000 PhD dissertation, not a protocol or a standard. To be truly RESTful, an architecture must follow six constraints.- Client-server separates the user interface from data storage.
- Stateless means no client context is stored on the server.
- Cacheable requires responses to declare if they can be reused.
- Layered system means the client does not know if it is connected to the end server or an intermediary.
- Uniform interface provides a standard way to communicate.
- Code on demand is optional and allows sending executable scripts to the client.
Recap
| Idea | What to remember |
|---|---|
| Resources | Resources are named by URIs |
| HTTP methods | Methods define the actions |
| Status codes | Status codes communicate the outcome |
| Stateless | Statelessness allows horizontal scaling |
| Safe and idempotent | Methods are categorized as safe and idempotent |
| REST | An architectural style rather than a strict protocol |
About TechPrep
Never walk into a technical interview unprepared again. TechPrep empowers software engineers to stop guessing and start getting offers. We provide the exact questions asked by tech companies across Data Structures & Algorithms, System Design, Low-Level Design & AI coding rounds. Don't leave your career up to chance. Join thousands of engineers who have successfully navigated the tech hiring maze and landed roles at top tech companies.