Open In App

How does an API Work ?

API stands for Application Programming Interface which helps software applications communicate with each other to exchange data, features, and functionality. This exchanged data is in the form of HTML, JSON, XML, and Text. In this article, we will discuss the workings of API.

We will discuss the following components of an API and how an API works:



1. API client:

The API client sends the request to the API server. This request can be triggered in many ways. For example, when a user clicks a button or enters a search term.



2. API request:

An API request contains the following components

3. API server:

The API client sends the request to the API server, which is responsible for handling authentication, validating input data, and retrieving or manipulating data.

4. API response:

Finally, the API server sends a response to the client. The API response typically includes the following components such as HTTP status codes, response headers and response body.

How does API work?

API’s work by sharing data between applications. The request is sent to the API, which retrieves the data and sends to the user. On the web, we use the HTTP protocol (which stands for Hyper Text Transfer Protocol).

Let us get the data from API using Postman.

Example API : https://jsonplaceholder.typicode.com/posts

Step 1 : Click the “+” button to create a new request as shown below

Step 2: In the URL bar, enter the endpoint of the API you want to interact with. Here, enter our public API https://jsonplaceholder.typicode.com/posts and click on “send” button to execute the request.

Making an API GET request in Postman

Step 3 : After clicking the send button, the server fetches for the “/posts” end point and sends the response which looks like this

Response sent by the server to the API

Types of API

There are four different types of APIs commonly used in web services: public, partner, private and composite.

API : https://jsonplaceholder.typicode.com/photos

Output :

A part of response sent by the API

Conclusion:

Application Programming Interface(API) is an intermediate between the software applications. It also helps in abstraction as it hides the internal complexity and gives the required information which we need. The API contains the URL, method, header and body. APIs follow the HTTP protocol to communicate, which has a specific request and response structure. Many third party applications use APIs to book the tickets or to make payments.


Article Tags :