REST (Representational State Transfer) is the most popular API architecture style today. APIs that follow REST rules are called RESTful APIs.
Key Characteristics
REST works based on Resources. Every piece of data (User, Product, Order) is considered a resource and has a unique address (URL/Endpoint).
HTTP Methods (Verbs)
In REST, we use HTTP verbs to determine "what to do" with that resource:
| Method | Function | SQL Analogy |
|---|---|---|
| GET | Retrieve data | SELECT |
| POST | Create new data | INSERT |
| PUT | Update data (replace) | UPDATE |
| PATCH | Update data (partial) | UPDATE |
| DELETE | Remove data | DELETE |
Endpoint Examples
Suppose we have an Online Store application:
bash
GET /products # Get all products
GET /products/12 # Get product with ID 12
POST /products # Add a new product
DELETE /products/12 # Delete product ID 12