Picture this: you want to watch a video of your favorite vlogger. First, you search for their name in subscriptions. Then, you choose an interesting video and start watching.
From the perspective of the user, it’s enough to press certain buttons and get the result. However, a simple action such as watching YouTube videos involves a complex process under the hood.
When you click on a video, the browser sends a request to the server. Once it receives an answer, the video is launched.
The problem is that each website uses different servers. All of them store information in a specific way. If the browser or application sends a request to the server incorrectly, it will not receive an answer and the desired web page will not be displayed.
(Basically, the user won’t get what they want!)
To avoid this issue, developers have created a way to help different programs communicate with each other and share data. It’s called API ― or Application Programming Interface. (It’s a set of rules and functions!)
There are a lot of different APIs. But 93.4% of API developers use a REST approach, finding it to be much easier than others in getting a website or app to provide data from a server to the user.
What is a REST API?
A REST (Representational State Transfer) API is one of the ways websites and applications interact with the server. It defines how data is transferred to a browser viewing a website.
It is like a contract between a client and a performer. The client is an application or website that requires data. And the performer is a server — it has that data. An API is the contract that specifies what data the client can get, and the terms for getting it.
REST APIs are a paradigm — or style — for developing APIs, which follow certain rules. If developers want something different, they could choose another type of API.
Why other APIs are less popular
Without a REST API, client-server interaction would be more difficult. Before that, there were XML-RPC, JSON-RPC, WSDL, and SOAP. They all have various shortcomings.
Other APIs are protocols. They use only one messaging format. For example, SOAP only uses XML. Therefore, SOAP is not suitable for most web products.
Other APIs are more complex. For example, they require the client to wrap messages in a specific “envelope” when using SOAP. It is time-consuming, makes the data heavier, and requires a lot of bandwidth.
Meanwhile, RPC users are required to know procedure names or parameters in a specific order. It makes product development more difficult and, again, more time-consuming. (See a trend here?)
REST follows a consistent pattern for interacting with entities, so the developer does not need to specifically learn or memorize what to do with every request. Thus, speeding up product development!
The five rules of a REST API
In general, there are five requirements for API design with REST:
Let’s go back to the example with the contract. When the client requires data, it asks the performer and gets it. The only type of interaction between the two is strictly business.
So that’s why a REST API only works with client-server systems. When your browser requests a web page from the YouTube server, it acts as a client. And the code of your favorite vlogger’s new video page is on one of YouTube’s servers.
In a client-server system, the client and the server exist independently and only occasionally interact. This makes such systems faster for product development and easier to work with.
The opposite of the client-server system is a layered environment, used by the above-mentioned APIs like SOAP and XML-RPC. It is also a performer, but a bureaucratized one, as the data must be approved at each level. As a result, the client takes plenty of time to receive the required data.
However, developers sometimes choose this kind of API, as multiple layers can help isolate and handle errors. In other words, they’re choosing the stability of the system over user comfort.
Furthermore, developers occasionally need to change the server logic. This could be due to the need for integrating with third-party APIs or services, which may require modifications to the server-side code to accommodate different data formats or protocols.
If you work with a layered environment, you have to rebuild the processes, as the format of the request — and other important details — will change, resulting in several ways the application and the server will cease to understand each other.
The client-server system simplifies development. If the server logic changes, the format of the request and responses will remain the same. It saves a lot of energy, time, and money!
This approach especially helps when creating large products. As you may remember, YouTube was a website first and only later became an app. Developers only needed to write the application, but not the server. And the system continues to work correctly.
The client and the performer make a new contract every time they interact, for each new project. The contract contains only information about the specific project and does not include their previous history. And statelessness is similar.
The server does not store data about past interactions with the client. Each request contains all the necessary information for processing.
When the browser sends a request about the video to the server, there is no information about the search for the vlogger — only about the video.
It is not possible to complete a previous request. Any new action requires a new one.
It reduces the load on the server if many clients are connected to it at the same time.
And if one of the requests gets lost, it won’t break the overall logic. After all, each of them has the necessary amount of information!
In practice, this is one of the most important day-to-day qualities of REST APIs for a developer.
Yes, it sounds like the layered environment we talked about before, but this is different. (Don’t be afraid, we explain everything below.)
The main elements of a layered system are proxy servers. They store some of the information and additionally process data. When there are several main servers, proxy servers distribute the load between them.
A layered environment does not have proxy servers. This is the type of system architecture in which a request must go through each layer.
Meanwhile, a layered system of a client-server model is simpler. There are many proxy servers, but the request only goes through the easiest and fastest way.
Put simply, the two are different. A layered environment complicates the server system structure and slows it down; a layered system complicates the structure of a client-server model but achieves maximum speed and efficiency for it.
Imagine a chain of bakeries in Virginia that makes cupcakes, and there is a customer in Norfolk who wants their cupcakes delivered to their house. They don’t even know if there’s a bakery branch in Norfolk ― only that the order will be delivered by any means.
The customer is the app and the bakery is a system of servers. In this scenario, an API is simply a way to call a bakery.
So the customer calls a bakery and orders cupcakes. Without an API, they would have to coordinate every step on the way to completing the order:
- What flour to buy?
- What baking molds do we need to bake cupcakes?
- When do we need to call the courier?
- What kind of car to drive to another city?
- Where can we fill up the car on the road?
Sounds like an awful lot of work, right?
Proxy servers in this example are bakery branches. The customer does not know where they will bake the cupcakes, and who will deliver them. They call a unified line for all branches across the state. The manager does the job of launching and controlling all the processes.
This structure helps to organize millions of queries between servers. And if a developer changes the main server or the client, it will still not affect important data, thanks to proxy servers. It helps to scale the system up.
Since they create a new contract for every new project, the client and the performer return to the cooperation history only when urgently needed (For example, if the projects are repeated). This removes the need for creating a new contract every time. That's how the principle of cacheability works.
If the server re-collects the necessary data for each request, you won’t see the video anytime soon: this increases the load on the system.
But the developers have found a solution. They decided to save some of the data — or cache it — on proxy servers, to avoid overloading the system with additional requests.
If the client and the performer speak different languages, they will not understand each other ― everyone will interpret the contract any way they please, inevitably leading to mistakes. The contract and the interaction must, therefore, be done in the same language.
The client and the server in a REST API speak the same language. When you wish to “like” a video on YouTube, the client calls the server in the format native to the platform, e.g. “Like it” instead of “I like it” or “I am into it” and so on.
The server must understand the request and process it without errors. This is important because the server stores data in one format and transmits it to the client in another. Typically, the client receives data in JSON or XML.
For the system to work smoothly, the response to the query for the new resource should be in the same format as the previous ones. The system will then work without errors.
How to learn a Rest API
Beginners can learn a REST API in different ways. The easiest and most effective way is TripleTen’s Software Engineering Bootcamp! The program has amassed all the necessary information to develop essential IT skills. You don't have to search for anything on your own.
In 10 months, you can work as a:
- Front end Developer
- Back end Developer
- Full-Stack Engineer
- Software Engineer*
* Requirements for Software Engineers are often compiled from the first three professions.
For a more in-depth study of a REST API on your own, try the following:
- Rapidapi: an interactive guide to help you understand APIs, REST, and other important things
- Insomnia: a cross-platform REST client. Here you can practice creating queries and automation
- PyRestTest: a Python-based REST API testing platform. It is the perfect way to test your future backend projects
Experienced developers advise practicing with real websites and servers. For example, GitHub has a useful repository with a huge number of free APIs that you can practice with.
A REST API is an approach that allows a product to communicate with a server in a straightforward manner.
It makes services flexible, productive, and able to remain operable even when one or more of its parts are broken.
A REST API makes website and application development much easier. It also enables simple data sharing between the client and server.
Land a career in IT
With the help of TripleTen, you can become a software engineer in just ten months! Career coaching then helps you find a job suitable for you. And if for some reason, you don’t find a job within six months of graduating, you will be reimbursed 100% of your tuition.