Introduction to REST
REST (Representational State Transfer) is a set of conventions for designing web APIs.
Core idea: resources
A REST API is organized around resources:
/users/users/posts/posts/orders/orders
You use HTTP methods to operate on them:
- GET
/users/usersβ list users - GET
/users/1/users/1β get one user - POST
/users/usersβ create user - PUT/PATCH
/users/1/users/1β update - DELETE
/users/1/users/1β delete
Status codes matter
- 200 OK β success
- 201 Created β created successfully
- 400 Bad Request β invalid request data
- 401 Unauthorized β missing/invalid auth
- 403 Forbidden β authenticated but not allowed
- 404 Not Found β resource doesnβt exist
Statelessness
REST APIs are typically stateless:
- every request contains everything needed (auth token, parameters)
Thatβs why token-based auth (JWT) is common.
A good REST mental model
false
flowchart LR Client -->|HTTP + JSON| API[Flask API] API -->|ORM| DB[(Database)] DB --> API API -->|JSON + status| Client
false
Practical tip
REST is a guideline, not a law.
Aim for:
- consistency
- clear error responses
- predictable URLs
π§ͺ Try It Yourself
Exercise 1 β Create a Flask App
Exercise 2 β Dynamic Route
Exercise 3 β Return JSON
If this helped you, consider buying me a coffee β
Buy me a coffeeWas this page helpful?
Let us know how we did
