Junior
What is REST API?
sobes.tech AI
Answer from AI
REST API is an architectural style for building distributed systems. The main principles of REST:
- Statelessness: Each request from the client to the server must contain all the information needed to process the request. The server does not store the client's state between requests.
- Client-Server: Clear separation of responsibilities between the client and the server. The client sends requests, and the server processes them.
- Cacheable: The server should indicate whether responses can be cached by the client or intermediary.
- Layered System: The client does not necessarily interact directly with the end server; it can interact through intermediate layers (proxies, load balancers).
- Uniform Interface: A single and standardized way of interaction between the client and the server. This principle includes:
- Identification of Resources: Resources (data) are identified by URLs.
- Manipulation of Resources Through Representations: The client interacts with resources by obtaining their representations (e.g., JSON, XML) and sending new representations to modify them.
- Self-descriptive Messages: Each message contains enough information to understand how to process it.
- HATEOAS (Hypertext As The Engine Of Application State): Resources should contain links (hyperlinks) to related resources and available actions.
REST API typically uses standard HTTP methods to perform operations on resources:
- GET: Retrieve a resource or a collection of resources.
- POST: Create a new resource.
- PUT: Fully update an existing resource.
- PATCH: Partially update an existing resource.
- DELETE: Remove a resource.
Example of a JSON representation of a resource:
{
"id": 1, // Identifier
"name": "Resource Name", // Resource name
"description": "Detailed description of the resource." // Resource description
}
Testing REST API includes checking:
- Functionality (correct responses to requests).
- Error handling.
- Performance.
- Security.
- Compliance with documentation.