Sobes.tech
Junior

What is REST API?

sobes.tech AI

Answer from AI

REST API is an architectural style, not a standard, for building distributed systems. It is based on principles such as statelessness, client-server architecture, and the use of standard HTTP methods (GET, POST, PUT, DELETE, PATCH) for resource operations.

Key principles of REST:

  • Stateless: The server does not store information about the client's state between requests. Each request contains all the necessary information for processing.
  • Client-Server: Clear separation of client and server. Each can evolve independently.
  • Cacheable: Responses can be marked as cacheable or non-cacheable, improving performance.
  • Layered System: The client cannot tell whether it is connected directly to the server or through intermediate layers.
  • Uniform Interface: Standardized ways of interacting with resources, including:
    • Resource identification (URI)
    • Manipulation of resources through representations
    • Self-descriptive messages
    • Hypermedia as the Engine of Application State (HATEOAS) - application state is managed through hypermedia links.

Example of using standard HTTP methods:

HTTP Method Action on resource (e.g., /users) Description
GET /users or /users/{id} Retrieve a list of users or a specific user.
POST /users Create a new user.
PUT /users/{id} Fully update user data by ID.
PATCH /users/{id} Partially update user data by ID.
DELETE /users/{id} Delete user by ID.

REST APIs are used for interaction between different systems and applications, such as between frontend and backend.