RESTful API

Learn about the REST API with the help of some examples.

What is a REST API?

The clients' programs use web APIs to communicate with the web servers. A web API takes the client's requests, interacts with the back-end servers, and responds back to the clients.

Many of today's APIs can be classified as REST APIs. Our purpose is not mere understanding but rather drawing insights into the REST architectural style of developing APIs.

Note: A REST API is a web API that conforms to the commonly used REST architectural style.

Many programming languages and protocols use CRUDCRUD refers to the four major functions: CREATE, READ, UPDATE, and DELETE, which are needed for an application or API to feel complete. The CRUD functions are commonly used to manipulate data on the server. operations for manipulating data. For example, in the SQL database, we use insert, select, update, and delete. Similarly, interacting with the REST application often involves CRUD operations because the REST-based applications are built around resources that need to be created, read, updated, and deleted. REST APIs are protocol agnostics; however, the underlying protocol they use widely for communication is HTTP. Therefore, the CRUD operations can be easily mapped to major HTTP methods, as shown in the following table.

CRUD One-to-One Mapping with HTTP Methods

CRUD Operation

HTTP Method

Description

CREATE

POST

POST is used to create a new resource, data, or a collection of data

READ

GET

GET is used to retrieve data from the server

UPDATE

PUT or PATCH

PUT is used to update the entire resource

PATCH is used to update a resource partially

DELETE

DELETE

DELETE is used to completely remove a resource from the server

What makes an API RESTful?

In the previous lesson, we studied the REST constraints, collectively called a web architectural style. Now, let's revisit those constraints from a different perspective. This time, we’ll see how an API should follow those constraints that make them a REST API.

  • Client-server: In the client-server setup, communication is initiated by the client via HTTP protocol by calling different HTTP methods. Since client and server are considered independent of each other, applications on both sides can evolve independently without affecting each other.

  • ...