REST - Representational State Transfer

REST is not a protocol but rather a set of architectural principles that define how web standards, such as HTTP and URIs, should be used to create scalable and maintainable web services

Key principles of REST include:

  1. Statelessness:
    • Each request from a client to a server must contain all the information needed to understand and fulfill that request. The server should not store any information about the client's state between requests. This design principle makes systems more scalable, as servers do not need to retain information about each client.
  2. Client-Server Architecture:
    • REST advocates for a separation of concerns between the client and the server. The client is responsible for the user interface and user experience, while the server is responsible for processing requests, managing resources, and handling business logic. This separation allows for independent development and scalability of the client and server components.
  3. HTTP Methods:
    RESTful communication relies on standard HTTP methods, also known as verbs, to perform operations on resources. The most commonly used HTTP methods in REST are:
    • GET: Retrieve a representation of a resource.
    • POST: Create a new resource.
    • PUT: Update an existing resource or create a new one if it doesn't exist.
    • DELETE: Remove a resource.
    • PATCH: Partially update a resource.
    • OPTIONS: Retrieve information about the communication options available for a resource.
    • HEAD: Retrieve only the headers of a resource.
  4. Representations:
    Resources in REST are represented in different formats, such as JSON (JavaScript Object Notation) or XML (eXtensible Markup Language). The client and server communicate by exchanging representations of these resources. For example, a client may send a JSON representation of a new user to create, and the server responds with a representation of the created user
  5. Uniform Interface:
    • The uniform interface is a set of constraints that simplifies and decouples the architecture, making it easier to understand and scale. It includes:
      • Resource Identification: Each resource (data or service) is identified by a unique URI.
      • Resource Manipulation through Representations: Resources are manipulated and exchanged using a standard set of representations, such as JSON or XML.
      • Self-Descriptive Messages: Each message from the server includes information on how to process it (e.g., using media types).
      • Hypermedia as the Engine of Application State (HATEOAS): Clients interact with the application entirely through hypermedia provided dynamically by the application servers.
  6. Stateless Communication:
    • RESTful communication between the client and server is stateless. Each request from a client to a server contains all the information needed to understand and process the request. This simplifies the server's task and allows for better scalability.
  7. Cacheability:
    • Responses from the server can be explicitly marked as cacheable or non-cacheable. Caching improves the efficiency and performance of the overall system by reducing the need for repeated requests.
  8. Layered System:
    • REST allows for a layered architecture, where each component (e.g., load balancers, gateways, or proxies) operates independently. This layered approach promotes flexibility, scalability, and ease of maintenance.

RESTful APIs (Application Programming Interfaces) are designed following the principles of REST. They use standard HTTP methods (GET, POST, PUT, DELETE, etc.) to perform operations on resources identified by URIs. RESTful APIs are widely used in web development for building scalable and interoperable systems.