In this article we will tell you everything you need to know about API or Application Programming Interface. Let’s start with explaining what is an API in pain English.
API in Plain English
API is an abbreviation for Application Programming Interface. API is a way for software systems or pieces of code to talk to each other. We use physical interfaces the whole day. The screen of your mobile phone is an interface through which you interact with the phone. I am typing this article on a keyboard. The keyboard is an interface for interacting with the word processing software. In the analogue world, a switch is an interface for a light bulb or a fan. We use interfaces throughout a day to interact with stuff around us. Think of APIs as the digital equivalent of physical interfaces.
Now let’s dive deeper into APIs.
Table of Contents
What is an API?
APIs refers to a set of programming instructions that enables the interaction between software components. Basically, an API service is a collection of specifications that computer systems use to “talk” to each other and share functionalities.
How do APIs work?
After talking about what is an API service, let’s now describe how APIs work. Foremost, it is important to mention that API is neither a database nor a server; rather, it is the code that controls the access points to the server.
For example, if you type https://www.wikipedia.org/ into your web browser, the browser connects to the Internet and sends a request to the website’s server. Then, the server interprets the received data and sends back a response to the browser, which also interprets the results and displays the required information in a human-readable format. This is how an API works—all these actions take place via an API.
Essentially, the interface that enables the web browser, also referred to as a client, and the website’s server to communicate is what is called an Application Programming Interface. Therefore, whenever you visit a website on the Internet, you’re sending and receiving data to a remote server using an API.
Here is a diagrammatic representation, sourced from Medium, which illustrates how APIs work:
To provide more explanation on what is an API, let’s use a familiar example of ordering food in a restaurant. If you’re in a restaurant, you select what you want to eat from the provided menu. While the kitchen is the “server” that will prepare your meal, there is an important missing link to relay your order to the kitchen and get you served at your table.
So, a waiter (or an API) comes in and takes your order (or request) and instructs the kitchen (or the server) about what you need. Consequently, the waiter delivers to you the meal (or the response).
Just like you’d consume the food without caring about the intricacies of preparing it, users usually consume APIs without really knowing what is taking place behind the scenes.
Different types of APIs
There are several methods for classifying APIs into different types. In this article, we’re going to talk about the following two main methods for classifying APIs:
- APIs by release policies
- APIs by specifications or protocols
APIs by release policies
According to release policies, APIs can be categorized into three main types:
- Open APIs—also called public APIs, implying that they are publicly available and anyone can access them without any restrictions.
- Partner APIs—these APIs are made available under partnership agreements, implying that you need to be granted a license before accessing them.
- Internal APIs—also called private APIs, implying that they can only be used within an organization.
APIs by specifications or protocols
The objective of API specifications is to stipulate rules or procedures that standardize the exchange of data between computing infrastructure. In the case of APIs, standardization implies the capability of disparate systems, created using various programming languages or various technologies, to interact with one another flawlessly.
Further, the classification of APIs by specifications can be divided into two main types:
- Web service APIs
- Web APIs
Web service APIs
Essentially, a web service refers to an application or a data source that is available over the Internet and uses an address, such as an URL, to allow access to its services. A web service is characterized by the provision of open standards and protocols that support interoperable communication between diverse software applications.
While there are several types of web service APIs, we’ll talk about two of the most common ones:
- SOAP (Simple Object Access Protocol)—this is a protocol that supports the structured exchange of data in the XML (extensible markup language) format. So, if you want to know about what is SOAP API, you’ll need to understand how the XML data format works.
- REST (Representational State Transfer)—it is a set of software architectural principles, and not a protocol, per se. REST is regarded as a simpler alternative to SOAP. REST API refers to APIs that comply with the REST design principles, make their data available as resources, which can be accessed using URLs that point to those resources. Unlike SOAP that supports only a single data format, REST supports a wide range of data formats, including plain text, HTML, XML, JSON, and YAML. Because of its simplicity and ability to support multiple formats, REST is a prevailing choice for creating APIs nowadays. So, if you want to know what is REST API used for, the possibilities are endless.
Essentially, a web API is an open-sourced concept, and not a technology, that can be utilized to create HTTP-based APIs. As the name suggests, it refers to an API available over the web, supports the HTTP protocol, and returns JSON or XML data type by default.
It is important to note that a web API can either be RESTful or not. Programmers can create web APIs using various technologies, such as .NET and Java.
Examples of APIs
With an API, you do not need to reinvent the wheel over and over again. As we’ll mention later in this article, one main benefit of APIs is that they allow you to build applications without having to code them from scratch. And, there are several APIs you can use to create a variety of transformative applications.
Here are two examples of APIs:
- IP Geo Location API—this free RESTful API allows you to get the geolocation data for any provided IP address. You can use it to display useful comprehensive information about the IP location of your website visitors, such as data about country location, city location, latitude and longitude coordinates, and time zone. Here is its screenshot:
- IBMWatsonTTS API—this free RESTful API lets you convert text to natural-sounding audio. With the API, you can create an innovative application that can convert written text into natural-sounding speech in a wide range of languages and tones. Here is its screenshot:
Common API terms
Here is an explanation of some common terms related to the use of APIs:
- API key—it refers to a unique identification code that is used to authenticate the user or application wanting to be given API access. An API key helps in controlling and tracking how it is being used, which can avert malicious users or fraudulent activities. Some APIs require unique keys before making a request, while others do not require.
- API call—it refers to making a request to the API for data retrieval, just like we’ve explained earlier.
- API endpoint—it refers to the end or touchpoint of the communication interaction between an API and a server. An endpoint can be considered as the URL of a service or a server. Simply, every endpoint is the point of entry where an API can access the resources it requires from a server to accomplish its stipulated tasks. As we’ve seen above, every API works using requests and responses. Whenever an API sends a request to a server, a response is always issued. The place where an API dispatches a request and where the response comes from is what is referred to as an endpoint.
- API token—it refers to an authentication scheme that uses cryptic strings, time-limited tokens, or other types of tokens to grant a user or an application API access. In token-based authentication, the API usually generates a piece of data that is used to prove the identity of the user or the application.
Using an API
To really get a sense about what is the meaning of an API, let’s demonstrate how you can use an API. And, the easiest way to begin using APIs is to go to the https://english.api.rakuten.net/ platform and search for any remote API you want. In this case, “remote” implies that the resources that the API interacts with are situated separately from the device making the request.
For example, you can use the Deezer API to listen to a music track. To make your first API request using the API, you can click on the GET * Search endpoint, which allows you to search for tracks on the Deezer music streaming platform.
Then, in the parameter field, enter the name of the artist or song you want to search. Lastly, click the Test Endpoint button and you’ll get a response data in a form easy for computers to interpret.
Here is a screenshot showing how to use the Deezer API:
Then, if we looked on the Response Body section, here’s a truncated version of the response data we got:
If you look at the above response closely, you’ll notice that, apart from other data, it has a link to the preview music we’ve searched for.
So, to play the track, we simply grab the preview link and post it on a web browser.
What are the benefits of using an API?
One of the greatest benefits of using APIs is that they make developers’ lives a lot easier. For example, let’s say you want to create an application that displays users’ geolocation details based on their IP address.
Instead of creating your own application from scratch, which could be demanding, you can use an IP geolocation API, such as the above-mentioned IP Geo Location API available on the Rakuten RapidAPI marketplace. With this API, you can provide accurate location data about a user and save yourself the hassle of having to sew your own application together, line of code by line of code.
If APIs were not available, developers would be obligated to do the hard work of creating such complex applications by themselves. However, the API creators have done all this work, allowing you to fetch the useful features and integrate them into your environment without many hurdles.
Furthermore, APIs allow developers to leverage the advanced capabilities of technology powerhouses. For example, the above-mentioned IBMWatsonTTS API lets you harness the sophisticated IBM’s machine learning technology to convert text into natural-sounding speech, something which could be difficult to realize with your own resources. What’s more, if there is any improved functionality, the API consumers can take advantage of it automatically and integrate it into their applications.
APIs also save on development costs and time. Programmers can create new applications, add new features to their applications, or complete other tasks simply by relying on the services of third-party providers. As such, developers may not need to deal with the source code or spend time trying to comprehend how the externally sourced solution works. Simply, they fetch their features and incorporate them into applications. In other words, APIs conceal the intricacies and inner details of systems, which greatly boost the productivity of developers.
If you have read this article until this far, then you should have an elaborate understanding about what APIs are and why they are such a big thing in the world of technology.
Consequently, you can go to any API documentation and start consuming it. Importantly, before performing API integration to create a new application or add features to an existing application, you should carry out sufficient API testing.
If you can test and see that it works according to your requirements, then API management will be an easy task. With proper management, the API will assist in taking the capabilities of your application to the next level.