What is an API Call?

Through an API call, a web application can query a microservice, i.e. ask other software for something: let's discover what it is and how it works

API Basics

  • Author: Alessandra Caraffa
  • //
  • Date: 14/04/2022
  • //
  • Reading time: 3 min

An API call is a process through which two pieces of software exchange data. When an application makes an API call, it sends another application a specific request that is received and processed by an API.

In order to understand what an API call is and how it works, we must first clarify the nature and role of APIs - Application Programming Interfaces. So let's see what APIs are, what an API call is, and, in more detail, how the interaction between one application and another takes place via an API call.

What are APIs and how they work

APIs are elements of an intermediate structure that allows different web applications to communicate with each other. APIs take care of exposing certain data to the outside world, so that the information can be shared with other applications that request it.

The API in the microservice architecture

A few years ago, the software world abandoned the traditional 'monolithic' approach and turned towards a new web application architecture, based instead on independent microservices.

This means that today, when using a social network, for instance, one does not interact with a huge piece of software that handles all the user's requests, but with a large array of small programmes that function autonomously: login, chat, etc. - in a scheme whereby each different function invokes a service.

Within an architecture based on microservices, APIs are the basic element of communication between software. Applications expose to the outside world the services they want to share with others via APIs - small operators that wait to be queried, i.e. to receive an API call.

The API's role is to listen, check the validity of communications and provide a response to each valid incoming request.

{ANCORA LEV=1}What is an API call?

An API call is the operation by which a web application queries a microservice, i.e. asks something from another piece of software.

You make an API call, for example, every time you log in or enter your credit card details to complete a payment, but also every time you do a Google search or choose a movie on Netflix.

What happens during an API call, from the point of view of an application requesting services from another piece of software, is more or less what happens in the more classical scheme of communication.

In the context of the exchange of information between applications, APIs are the medium, i.e. the means of communication that enables the exchange of information between a sender software, which in this case is the requester or client, and the recipient program, or server.

In this sense, the API call is the basis of the microservice architecture: the APIs are the individual 'receivers' waiting for a call, while the API call is the process that defines the role of the API in the interaction between software.

As for the message in the strict sense, however, there are several requests that can be made via an API call.

API Calls Rest: Predicates

Among the possible approaches to microservices architecture, the most widespread is the one called RESTful or Rest, a kind of 'extended' standard to adhere to which certain structural constraints (e.g. manipulation of resources through representations or self-descriptiveness of messages) are required.

The various types of API request most commonly used today correspond to 5 possible HTTP predicates typical of the Rest architectural approach:

  • GET: the application requests information from another;
  • POST: a request is made for the creation of new information;
  • PUT: a request is made for the whole of the information to be replaced;
  • PATCH: the application requests the modification of part of the information;
  • DELETE: the application requests that information be deleted.

Elements of a Rest API Call

Within a microservice structure of the Rest type, everything between the client's request and the server's response takes place on an intermediate layer between the application and the server (the API is not by chance part of the so-called middleware). This is also where the elements that constitute an API call are located, namely:

  • Endpoint: this is the 'physical' address of the API, the point from which the Rest server is listening, waiting for requests. Generally the endpoint describes its function, e.g. /film contains the list of films which can be queried via an API call;
  • Method: the type of request that can be made via the HTTP verbs GET, POST, PATCH, etc. is called a method;
  • Headers: these are details that applications exchange for the purpose of communication, both in the request and in the response phase. Among the most common headers in calls is 'host', which requires the IP from which the request originates;
  • Data, or message body: this is the content of the interaction between applications, it contains the information that is intended to be passed from one programme to another. This option is only used with the POST, PUT, PATCH verbs.

One of the typical constraints of the Rest approach concerns the server-client relationship: the two applications must be able to evolve separately, without any interdependent relationship. That is, in order to communicate, the server and client applications must only and exclusively know the URL of the resource, i.e. the way to reach it.

What happens during a Rest API call

In this sense, the appearance of a Rest API call corresponds with the URL of the resource: the call is made by directly querying the endpoint from which a response is expected, i.e. invoking a given URL.

Assuming that the endpoint is correct, as a first step the client checks the available options by means of the so-called Pre-flight, a prior request that allows it to know the available communication methods and the type of authentication required to execute the call (often username and password or a secret token).

The application receiving the API call responds with a list of available predicates and any other requirements. The client formulates the API request; if it is valid, the API communicates the request to the external programme, and once it has received a response, it distributes the data to the programme that had requested it.

The API call is immediate and synchronous: once an API has been queried, the client application stops its calls until it receives a response or a time-out message.

 

Access reliable, high quality data!

Discover over 380 services

in the Marketplace Openapi.com

DISCOVER NOW

What is an API Call?

Share on: