<strong>REST (Representational State Transfer)</strong> is an architectural style for building APIs. It uses standard HTTP methods (GET, POST, PUT, DELETE) to perform operations on resources, making APIs predictable and easy to use.
The Library Analogy
REST is like a library's catalog system. You use standard methods (search, borrow, return) to interact with books. You don't need to know where books are storedβyou just follow the system.
Books (Resources)
Data you want to access
Catalog System (REST)
Organized way to find books
Librarian (Server)
Manages the books
HTTP Request
Routes to Resource
Returns Data
Client sends HTTP request
GET /users/123 - Request user data
API routes to resource
Maps URL to the users resource
Server processes request
Fetches user 123 from database
Returns JSON response
Sends back user data in JSON format
Wrong
"REST means using JSON" or "Any HTTP API is REST"
Correct
REST is an <strong>architectural style</strong> with specific constraints: stateless communication, resource-based URLs, standard HTTP methods, and uniform interfaces.
A social media app using REST API:
GET /posts - Fetch all posts
POST /posts - Create a new post
PUT /posts/123 - Update post 123
DELETE /posts/123 - Delete post 123