API Fundamentals
/Beginner
What is REST?
Definition
REST (Representational State Transfer) is an architectural style for designing networked applications, relying on a stateless, client-server, cacheable communications protocol (almost always HTTP).
Explain Like I'm New
REST is a set of rules for how to build Web APIs so they are clean, predictable, and logical. Before REST, developers just made up random URLs like `myapi.com/delete_user_now_please_5`. REST says: 'No, be organized. Use standard HTTP methods on noun-based URLs, like `DELETE /users/5`.'
Real World Example
If you know an API is RESTful, and you want to fetch a list of articles, you immediately guess the URL is `GET /articles`. You don't even have to read the documentation to guess it, because REST is a universal standard.
Common Use Cases
- •Building Web APIs
- •Microservices communication
Terminal Output
bash / terminal
/*
Comparing a Non-REST API to a RESTful API
*/
// ❌ MESSY, NON-RESTful API (Verb-based URLs, random methods)
POST /getUsers
GET /createNewUser?name=John
POST /updateUser123
GET /delete-user-by-id/123
// ✅ CLEAN RESTful API (Noun-based URLs, strict HTTP Methods)
GET /users // Read all users
POST /users // Create a new user
GET /users/123 // Read user #123
PUT /users/123 // Update user #123
DELETE /users/123 // Delete user #123
Interview Questions
basic
- Does REST dictate what programming language or database you must use?
intermediate
- What does the 'Stateless' constraint in REST actually mean?