DEV Community

Cover image for What exactly is an API
Jima Victor
Jima Victor

Posted on • Originally published at webcodespace.com

What exactly is an API

Introduction

One of the terms thrown around a lot in the world of software development is "API" (Application Programming Interface). In fact, the term "API" is as popular as it is relevant in the field of software engineering.

As a beginner in programming, I had some issues understanding what the term "API" meant, and I believe a lot of beginners out there are facing a similar problem too. If you are one of those finding it difficult to understand what exactly an API is, then this article is for you.

In this article, I'm going to be explaining what an API is, providing different examples of an API, and everything you need to properly understand what an API is.

Let's get started!

What is an API

Simply put, an API is a standardized means through which an application can communicate, interact or share resources with another. You can call it an interface if you will. An API is to programmers, what a UI is, to users.

A lot of resources online use the restaurant analogy to explain APIs, which is great. However, I like to think of an API as a ladder that enables you to change a light bulb.

You can compare an API to a ladder that provides access to a light bulb. Just like how a ladder allows someone to reach a lightbulb that is out of reach, an API enables access to certain functionalities or data that may be otherwise inaccessible. The API defines the steps (or "rungs" of the ladder) that developers can use to interact with the underlying system or service, just as the ladder provides steps for someone to reach the light bulb.

The main benefit of APIs lies in the fact that it abstracts away the low-level details of how a system works, and gives you an easier way of accessing the functionalities of that system.

Let's take the DOM API for example, the DOM API provides a standardized way for developers to interact with HTML documents in web browsers. It abstracts away the low-level details of how the DOM (Document Object Model) is implemented, allowing developers to manipulate the structure, content, and styling of web pages using a set of classes and interfaces. This abstraction simplifies web development by providing a consistent interface for accessing and modifying HTML elements, regardless of the underlying browser implementation.

Difference between APIs and REST APIs

Today, it is very easy for a newbie to think that programming is all about the web. Due to the popularity of web programming, some developers think APIs and REST APIs are the same thing. They're not!

As previously explained, an API is a standardized means through which an application can communicate, interact or share resources with another. From this explanation, you can see that REST APIs qualify as APIs, but they do not represent the entire idea of APIs. You can think of them as a subset of APIs.

What is an API

The DOM API is not a REST API but it is still an API.

The Java Swing API is not a REST API but it is still an API.

The Windows Registry API is not a REST API but it is still an API.

The OpenGL API is not a REST API but it is still an API.

The DirectX API is not a REST API but it is still an API.

The Vulkan API is not a REST API but it is still an API.

So what is the takeaway? All REST APIs are APIs, but not all APIs are REST APIs.

REST APIs are APIs that follow the principles of the REST (Representational State Transfer) architecture.
The REST architecture is an architecture that is used to design APIs that allow developers to communicate with applications using the HTTP protocol. Not all APIs are designed like this.

You can learn more about REST APIs and their principles in this article.

Difference between APIs and Libraries

Another area where there is a confusion is distinguishing between APIs and libraries.

A library, is a collection of pre-written code or functions that can be used by developers to perform specific tasks or implement certain functionality. Libraries are typically packaged as compiled code or source code that developers can include in their own projects.

However, in order to leverage the functionality of these libraries, an API has to be provided. This API comes in form of the list of methods, functions, classes, and other interfaces provided by the library to its users.

So what is the takeaway? The library provides the functionality, while the library's API provides a way to access this functionality through the list of methods, functions, classes, and other interfaces that it provides.

A very common example would be the React library.

The React library provides the functionality of building user interfaces for web applications. This functionality can be accessed using the React library's API, which includes hooks, such as useState, useEffect, useContext, etc. These hooks allow developers to add state and lifecycle features to functional components.
Also part of the React library's API, are components, which allow developers to encapsulate reusable pieces of UI.

Conclusion

APIs are a very important aspect of programming. They help us (as developers) abstract away all of the low-level details while providing us with a standardized means for accessing the functionalities of an application. There are different types of APIs, some are provided for applications that are accessible locally, while others are provided for applications that are accessible over a network. These APIs are also present in frameworks, libraries, and platforms, enabling developers to integrate their code with existing software seamlessly. By utilizing APIs, developers can save time and effort by leveraging pre-built functionalities rather than reinventing the wheel.

Top comments (0)