Sobes.tech
Senior

What is the difference between REST and RPC? What does stateless mean in the context of REST?

sobes.tech AI

Answer from AI

REST (Representational State Transfer) and RPC (Remote Procedure Call) are two different approaches to organizing interaction between a client and a server.

  • REST:

    • Based on resources identified by URIs.
    • Uses standard HTTP methods (GET, POST, PUT, DELETE) for resource operations.
    • Clients interact with resources through their representations (e.g., JSON).
    • An architectural style focused on the state of the representation.
    • Stateless — each request from a client to a server contains all the necessary information for processing; the server does not store state between requests. This simplifies scaling and increases reliability.
  • RPC:

    • Based on calling remote procedures or functions.
    • Clients invoke server methods with parameters, and the server executes and returns the result.
    • Less resource-oriented, more action-oriented.
    • Can use different protocols and formats (e.g., JSON-RPC, XML-RPC, gRPC).

Stateless in the context of REST means that the server does not store any information about the client's state between requests. Each request must contain all necessary information (e.g., authentication data, parameters) so that the server can process it independently of previous requests. This simplifies scaling and increases system fault tolerance.