Features
- Resource-based URL structure
- Standard HTTP methods (GET, POST, PUT, DELETE)
- Stateless communication between client and server
- Cacheable responses with HTTP headers
Pros
- Universal — understood by every language and platform
- Simple mental model based on HTTP standards
- Excellent tooling, caching, and CDN support
Cons
- Over-fetching and under-fetching data
- No built-in type safety or contract enforcement
- Versioning APIs can become complex
Overview
REST (Representational State Transfer) is an architectural style for designing networked applications. It uses standard HTTP methods to perform CRUD operations on resources identified by URLs. REST has been the dominant API paradigm for web development since the mid-2000s.
RESTful APIs are stateless, meaning each request contains all the information needed to process it. This simplicity makes REST APIs easy to understand, cache, and scale. Combined with OpenAPI/Swagger for documentation, REST remains the most widely adopted approach for web APIs.
When to Use
REST is the right default for public APIs consumed by multiple clients, for simple CRUD applications, and when you need maximum compatibility across different languages and platforms. Consider GraphQL for complex data requirements or tRPC for internal TypeScript APIs.
Getting Started
// RESTful route structure
// GET /api/users - List users
// GET /api/users/:id - Get single user
// POST /api/users - Create user
// PUT /api/users/:id - Update user
// DELETE /api/users/:id - Delete user
app.get("/api/users/:id", async (req, res) => {
const user = await db.users.findById(req.params.id);
res.json(user);
});