A REST API (Representational State Transfer API) is an architectural style for building web services. It uses standard HTTP methods and is designed around resources (things like users, products, or orders), each identified by a URL.
Core Principles
REST APIs follow six key principles:
- Client-Server: The frontend and backend are separate and independent
- Stateless: Each request contains all the information needed to process it
- Cacheable: Responses can be cached to improve performance
- Uniform Interface: Consistent, predictable URL patterns and methods
- Layered System: Can have intermediary servers (load balancers, caches)
- Code on Demand (optional): Servers can send executable code to clients
HTTP Methods in REST
- GET: Retrieve data (e.g., GET /users/123 returns user 123)
- POST: Create new data (e.g., POST /users creates a new user)
- PUT: Update existing data (e.g., PUT /users/123 updates user 123)
- DELETE: Remove data (e.g., DELETE /users/123 removes user 123)
Example
To get a list of products from an e-commerce API:
GET https://api.store.com/products
The server responds with JSON data containing the products.
Why REST is Popular
REST APIs are simple, scalable, and work with any programming language. They're the standard for most web and mobile applications today.