What is a REST API

May 9, 2023 MrAnyx 3 min to read

What is an REST API

A REST API (Representational State Transfer Application Programming Interface) is a way for different computer programs to talk to each other over the internet. It uses a set of rules and standards that define how data should be exchanged between systems.

The main purpose of a REST API is to make it easier for different systems to work together. For example, if you're building a mobile app that needs to access data from a web server, you can use a REST API to send and receive information. This makes it possible for your app to work seamlessly with the web server, without the need for complicated integration code.

What are the key features

One of the key features of a REST API is that it is stateless. This means that each request contains all the information needed for the server to process it, without the need for the server to keep track of any session information. This makes it easier to scale a REST API, because the server doesn't need to worry about managing multiple sessions.

Another important feature of a REST API is its uniform interface. This means that all requests and responses follow a consistent format, which makes it easier for developers to understand and work with.

Overall, a REST API is a powerful tool for building modern web applications that need to communicate with other systems over the internet. By adhering to the principles of REST, developers can create web services that are flexible, scalable, and widely supported across different platforms and programming languages.

The difference with SOAP API

In the other hand, SOAP (Simple Object Access Protocol) is a protocol for exchanging structured information between different systems over the internet. It is an older technology that was widely used before REST APIs became popular.

One of the main differences between SOAP and REST APIs is that SOAP typically uses XML (Extensible Markup Language) to structure the data being exchanged, while REST APIs often use JSON (JavaScript Object Notation) or other lightweight formats.

JSON is a popular choice for REST APIs because it is a lightweight data format that is easy to read and write, and is supported by most programming languages. JSON also has a more compact structure than XML, which can help to reduce the size of data being transmitted over the internet, and can improve performance.

Another key difference between SOAP and REST APIs is that SOAP is more tightly coupled, meaning that the client and server must have a predefined agreement about the format of the data being exchanged. This can make it more difficult to evolve a SOAP API over time, because any changes to the data format can break compatibility with existing clients.

In contrast, REST APIs are designed to be loosely coupled, meaning that the client and server don't need to have a predefined agreement about the format of the data being exchanged. This makes it easier to evolve a REST API over time, because clients can adapt to changes in the data format without breaking compatibility.

Overall, while SOAP and REST APIs both provide a way for different systems to communicate with each other over the internet, REST APIs are often preferred because they are more lightweight, flexible, and easier to evolve over time. And when it comes to choosing a data format for a REST API, JSON is often a popular choice due to its simplicity, compactness, and wide support across different programming languages.

Other types of APIs

There are other types of APIs, such as GraphQL or RPC, but in this course we will focus on REST APIs. Each of them has its own advantages and disadvantages. For example, GraphQL APIs return the data the user wants, while REST APIs return data in the same format every time. But as a newer technology, it can be more difficult to use.

This work is made available under the terms of the license Licence Creative Commons