What is API?
API (Application Programming Interface) is a set of rules and protocols that allows interaction between different software components or services.
What is REST?
REST = Representational State Transfer
Software architectural style for building distributed hypermedia
Set of following architectural principles (REST)
Resource Orientation
Unique Resource Identification
Stateless Client/Server Communication
Each request from the client contains all the necessary data to process the request on the server. The server does not persist state between requests from the same client, making it easier to scale and improve system reliability.
Resource Manipulation
Uniform Interface: The RESTful API provides a uniform interface for interacting with resources. This includes using standard HTTP methods (GET, POST, PUT, DELETE, and others) to perform operations on resources, as well as uniform conventions for identifying resources via URI (Uniform Resource Identifier), data formatting (e.g., JSON, XML), and others. aspects of interaction with resources.
HTTP-methods and REST
The RESTful API relies on a limited set of HTTP methods such as GET, POST, PUT, and DELETE to perform operations on resources on the server, while the API may use different methods depending on the implementation.
REST FORMATS
An API can have various data transfer formats such as XML, JSON, SOAP, etc. while a RESTful API usually uses the JSON format for data transfer.
REST Identification
The RESTful API uses a URI (Uniform Resource Identifier) to identify resources on the server, while an API can use a variety of methods and ways to identify resources.
Stateless
The RESTful API is built on the principle of “Stateless” (stateless), which means that each request from the client contains all the necessary data to process the request on the server. The API, in turn, can be either “Stateless” or “Stateful” (stateful), depending on the implementation.
REST HTTP status codes
RESTful APIs typically use HTTP status codes to indicate the result of an operation, such as 200 OK, 201 Created, 404 Not Found, etc. The API can also use HTTP status codes, but this is not a requirement.
Caching
Caching: The RESTful API supports caching, which allows clients to keep local copies of resources on their side to improve performance and reduce server load.
Client-server architecture
Client-server architecture: The system is divided into a client part, which is responsible for the user interface and user interaction, and a server part, which processes requests from clients and manages resources. This allows you to independently develop the client and server parts of the system.
REST != HTTP
HTTP (Hypertext Transfer Protocol) is one of the most common protocols used to implement RESTful APIs. However, REST and HTTP are different things. REST defines the architectural principles for organizing communication between a client and a server, while HTTP is a data transfer protocol used to exchange information between a client and a server.