What is a Rest API?

man with question marks surrounding

Imagine planning a summer vacation; however, you do not know where you want to go. Logically, you would like to go to a travel agent to find the best destination at the best price. This agent would give you information, brochures, and whatever else they have to offer to help you make the best decision. Once you decide where you want to go, the agent will book your tickets, hotels, rental cars, etc.

This travel agent had a similar role as an API in your vacation planning. While the agent connects you with the hotels, airlines, and rental agencies, an API connects you with data in some of your most common computer programs.

A Closer Look at APIs

API stands for Application Programming Interface, and it establishes a connection between programs. The user would create a request for data, in which this request would have to be structured in a specific way and then sent to the API. The API would then send back the needed data if the request met all requirements for the program. For some programs, authorization would be necessary to retrieve the data, and all APIs come with documentation of the data available to the user.

An API was designed in a way to make it seem more like a function and feel like locally executing code. However, this design made it challenging to use on an HTTP protocol. This is because an API is all about connecting the users with the servers. An HTTP protocol is connection-less, making it hard for the API to transition to the web.

Critical Differentiators for REST APIs

man with Large Magnifying glass

A computer scientist named Roy Fielding developed six architectural constraints or standards which guide the creation of processes that enable us to retrieve data from the web. These six constraints make up what is called "REST," or Representational State Transfer. Any API that adheres to the constraints of REST is considered to be RESTful. In other words, they are REST APIs.

With REST APIs, we can connect with other servers using the HTTP protocol. This means users can Create, Read, Update, and Delete data. These four operations are known as CRUD operations, and they are the most commonly used methods in a REST API. What allows us to do these CRUD operations is that REST simplifies the communication process by giving different HTTP Methods, Operations, or Verbs, which are used to send requests to the servers.

man standing pointing at light bulb

For an API to be RESTful, it must adhere to specific criteria:

  • All interfaces within your system should be uniform. In other words, once a user or developer gets comfortable with one of your APIs, they should feel comfortable using all other APIs.
  • The client applications and the server applications should be independent and able to evolve separately. Either clients or servers can be replaced within a system without altering their interface.
  • The servers should not take any data over to a new session. This means the API must be stateless. The client should be responsible for managing the state of the application.
  • Resources should be cacheable when applicable, and the resources must declare themselves cacheable. This is to improve scalability and performance further.
  • All systems must be layered. Meaning your deployment of APIs will be on one server while the storage of data will be on another. Also, the authentication of the request will be on a completely different server. The client should not be able to tell if they are on the end server or one in between.
  • The last constraint, if you want to call it a constraint as it is optional, is that code should be available on-demand to the client. A client should be able to request executable code from the server, improving their functionality.

Though REST must follow these six constraints, it is still more straightforward to use than its predecessors. REST, at its core, makes it possible to build large, ultra-scalable systems that provide clients with an easy-to-use program.