A Basic Introduction to APIs
Tags: beginners, webdev, programming, database
Published: 2019-05-15 00:10:27

---
title: A Basic Introduction to APIs
published: true
cover_image: https://thepracticaldev.s3.amazonaws.com/i/pt35nzgyvrlufyefckfm.png
tags: beginner, webdev, programming, database
---

Ever since I started coding a few months ago, I have heard the three letters API being thrown around. For those who have experience with programming, it is a very familiar term, but what exactly is it? My first experience with an API actually came from my very [first coding project](https://github.com/njenga-kariuki/module-one-final-project-guidelines-seattle-web-career-021819). For this project, my partner and I were given the task of building a CLI application. The application utilized a NBA stats API and would return the stats of any player that a user would input in the terminal. At this point in time, I thought APIs were simply databases that you could pull information from. This is a common misconception for new users considering APIs are regularly used to fetch data. However, the API is not where the actual data is coming from.

## **What is an API?**
API is an acronym that stands for Application Programming Interface. More specifically, the definition is "a set of functions and procedures allowing the creation of applications that access the features or data of an operating system, application, or other service". It isn't actually a database, but rather a part of the server that allows different applications to communicate with one another. APIs act as a middle man with the responsibility of receiving requests and returning responses. An easy way to think about this is to imagine the flow in a restaurant. You the customer(your application) orders a meal through the waiter(API), who then relays your order to the kitchen(the system). The kitchen makes the food(response) and the waiter brings it back to you. It is important to point out that these responses are not strictly limited to just data and that different APIs can be used for various purposes.

![](https://thepracticaldev.s3.amazonaws.com/i/7pdjzuspuyyg0spmc03b.png)
<figcaption>
Flow of using an API
</figcaption>


## **Common Types of APIs**
One of the most commonly used types of APIs are web APIs. Web APIs allow different applications to communicate and connect with each other through the Internet. Many of these are based around the HTTP protocol, which means they can be accessed by almost all programming languages. Web APIs can further be categorized into public and private. Public APIs are generally available to anybody who wants to use them. Private APIs, however, restrict their access to the general public. These APIs are usually used by companies and require a key for access. Access can be bought depending on the API. Another type is library-based APIs. Like the name states, this type references a library of code or functions that can be used to create connections between different applications.

![](https://thepracticaldev.s3.amazonaws.com/i/8nk2plbis51kkuz9hi78.png)


## **Why use an API?**
One reason that APIs should be used is, because they makes applications more efficient. When considering just data, rather than having your application collect data on its own, using an API that has already collected the data you are looking for and retrieving it saves a lot of time and effort. APIs are also useful when you want to use preexisting functionalities within your application rather than creating them from scratch. Other than streamlining your applications, APIs provide another layer of security by acting as a gate when information is being passed.

## **Takeaways**
Taking into account all the benefits of using APIs, I highly recommend using them whenever you get the chance to. However, not all APIs work in the same way. From personal experience, I can confidently say that some are better than others. Before using a specific API, I would definitely look over it to see if it will actually be beneficial to whatever you are planning to use it for. Thanks for reading!

![](https://thepracticaldev.s3.amazonaws.com/i/z7vk5ldiapajjsq1k68a.gif)