REST (Representational State Transfer) is an architectural style for designing networked applications, particularly web services. RESTful APIs allow clients to communicate with servers in a standardized and stateless way.
- Statelessness: Each request from client to server must contain all information needed to understand and process the request. The server does not store any session data.
- Client-Server Architecture: The client and server are separate, allowing each to evolve independently.
- Uniform Interface: Resources are identified via URLs, and interaction is performed through standard HTTP methods.
- Resource-Based: Everything is treated as a resource identified by a unique URI.
- Representation: Resources can have multiple representations, such as JSON, XML, or HTML.
- Cacheable: Responses must define themselves as cacheable or non-cacheable to improve client efficiency.
- GET: Retrieve data from the server.
- POST: Create new resources.
- PUT: Update or replace existing resources.
- PATCH: Apply partial updates.
- DELETE: Remove resources.
- Use nouns for resource names (
/users
, /orders
).
- Use plural nouns for collections.
- Support filtering, sorting, and pagination in query parameters.
- Return appropriate HTTP status codes (
200 OK
, 201 Created
, 404 Not Found
, etc.).
- Use consistent naming conventions (camelCase or snake_case).
- Provide meaningful error messages with error codes.