What is REST API?
Nowadays, the usage of a REST API is very common, whether we’re talking about front-end or back-end. But what is REST?
REST (Representational State Transfer) is a software architecture that is already 15 years old and closely related to the HTTP protocol, in which everything is handled as a resource. In this type of architecture, both client and server communicate by exchanging resources (data) through requests, without keeping or remembering states of specific resources: meaning that each request is independent.
The fact that it doesn’t need to keep data about each resource, nor from past requests, provides the REST services with a better, more powerful and more efficient performance when compared to other web services such as SOAP (Simple Object Access Protocol).
If the service has been around for over 10 years, why is it so popular now?
The growth of web services, the expansion of its usage and today’s diversity of clients (devices) made the SOAP services less efficient, due to its complexity. Meanwhile, the REST services simplified the manipulation and transport of data, which gave them an advantage when compared to the first ones.
We can say REST services have the following characteristics:
- Everything is a resource.
- Any resource should have a unique identifier and should be accessible through an URL.
- The resource manipulation is done using HTTP methods.
- The resources can have multiple representations.
- Stateless communications: each request is independent and the server doesn’t save data from previous requests
Characteristics like these are precisely the ones that allowed REST services to emerge as the main choice of architecture style for API, using JSON as the typical data format, and SOAP services to lose ground.
The main advantage of using REST is its performance and scalability.
The fact that this service has big amounts of data accessible to many users is very important, since it allows REST to scale easily and and also handle a bigger number of requests. This becomes almost impossible for services that save the data from all the states of each resource or from previous requests, specially when a fast response time is necessary.
Scaling a REST service is quite simple and quick – it is possible to migrate it to other servers or making changes of any kind in the database, every time the data of each request is correctly sent.
All this makes REST services one of the best and most popular choice when implementing an API, nowadays.