REST (Representational State Transfer) is an architectural style used for designing networked applications, particularly web services. It was introduced by Roy Fielding in his doctoral dissertation in 2000 and has since become one of the most popular paradigms for building web APIs, especially for distributed systems and services on the web. RESTful APIs (or RESTful web services) are commonly used in web applications to provide communication between client and server over the HTTP protocol.
REST is based on a set of principles that emphasize simplicity, scalability, and statelessness. The core constraints that define REST are:
Each request from a client to a server must contain all the necessary information for the server to understand and process the request. The server does not store any information about previous requests. This means that each request is independent, and the server does not maintain session or context information between requests.
REST follows a client-server model, where the client and server are separate entities. The client sends requests to the server, which processes them and returns a response. The client and server communicate over a network (usually HTTP), and the server is responsible for handling requests, while the client handles the user interface and user interaction.
RESTful web services have a uniform interface, which simplifies the architecture and decouples the client and server. The uniform interface refers to a set of standard operations that clients can perform on resources. The main operations are:
In REST, the primary concept is resources. A resource is any piece of data or object that can be accessed and manipulated via a REST API. Each resource is identified by a URL (Uniform Resource Locator). For example, a RESTful service for a blog may have the following resources:
/posts: Represents a collection of blog posts./posts/123: Represents a single blog post with the ID 123.Resources are typically represented in JSON or XML format, although JSON is by far the most common format due to its simplicity and efficiency.
When a client requests a resource, the server responds with the resource's representation, which is typically a data format like JSON or XML. This representation contains all the necessary information for the client to understand and interact with the resource. The client can modify the resource’s state by sending updates to the server using the proper HTTP methods.
Each HTTP request made by the client to the server must be self-contained. The server does not store any session or context information. This ensures that RESTful services are scalable and can handle a large number of requests without needing to store information about previous interactions.
In REST, responses from the server can be explicitly marked as cacheable or non-cacheable. This helps improve performance by allowing responses to be stored and reused without needing to make an expensive request to the server every time. HTTP headers, such as Cache-Control, are typically used to indicate whether a response is cacheable.
RESTful web services use standard HTTP methods to interact with resources:
GET:
GET /users/123 retrieves the user with ID 123.POST:
POST /users sends data to create a new user.PUT:
PUT /users/123 updates the user with ID 123.DELETE:
DELETE /users/123 deletes the user with ID 123.PATCH:
PATCH /users/123 might update the user's email address or password.RESTful services are designed to scale easily because they are stateless, which means that the server does not need to track any session state between requests. This allows REST APIs to handle large volumes of requests without being burdened by session management.
REST APIs are simple to understand and use. The architecture is built around standard HTTP methods, and the data is typically returned in a lightweight format like JSON. The simplicity of REST makes it ideal for mobile and web applications where performance and ease of use are critical.
Since RESTful APIs use HTTP and standard data formats (like JSON), they can be easily consumed by a wide range of clients across different platforms. This makes REST ideal for integrating different applications, services, and platforms.
The stateless nature of RESTful services makes them highly scalable. Each request from the client is independent, and the server does not need to store information about previous requests. This makes it easier to distribute the workload and handle high traffic.
Since REST is designed with stateless communication, responses can be cached for better performance. Responses can be marked as cacheable, so clients can reuse them without making a new request to the server.
In REST, the client and server are independent. The client focuses on the user interface and experience, while the server is responsible for handling requests and managing data. This separation allows each component to evolve independently.
REST has become the dominant choice for web services and APIs due to its simplicity, scalability, and ease of integration. Its stateless nature and support for lightweight data formats like JSON make it an ideal choice for modern web and mobile applications, while its ability to leverage HTTP makes it easy to use with existing web infrastructure. While SOAP still has its place in enterprise applications, especially when advanced features like security and transactions are required, REST is generally preferred for most modern web services.
Open this section to load past papers