Understanding REST

Duration: 10 min  •  Difficulty: Medium

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:

MethodFunctionSQL Analogy
GETRetrieve dataSELECT
POSTCreate new dataINSERT
PUTUpdate data (replace)UPDATE
PATCHUpdate data (partial)UPDATE
DELETERemove dataDELETE

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