Getting started with Application Programming Interface (API)
Tags: beginners, api, tutorial
Published: 2022-10-16 10:08:33

## Introduction

Connectivity is a wonderful thing that allows us to have access to the entire world at our fingertips. You can get the latest trends or news on your phone. We can post, pick, book a doctor's appointment or even a flight, buy a product, and open an online store. All of this is possible by the simple use of Application Programming Interfaces (API).

### Prerequisite

To follow along with this article:

- Download any IDE of your choice. I prefer [Visual Studio Code](https://code.visualstudio.com/download)

- It is advisable to have an understanding of [JavaScript](https://www.w3schools.com/js/) or libraries like [React.js](https://reactjs.org/)


## What is an Application Programming Interface (API)?

An API, which stands for Application Programming Interface, is a third-party integration that allows applications to communicate with one another. They act as a middle-man or messenger, receiving a **client request**, sending it to the web server, and returning to the client with the data as a **response**. An API is used every time you use a social media app, send an instant message, or check the weather on your phone.


## Why learn Application Programming Interfaces (API)

- Application Programming Interface (API) enables communication between computers. Through API, companies update workflows easily and quickly, making them more productive.
Companies such as Amazon, Salesforce, or Twitter can easily integrate services into their systems.

- API allows you to easily assess data or get information. This information could be about the weather or other topics. An example of an API is [open weather API](https://openweathermap.org/). This makes the application easier to work with.

- API integrates content into a website's development and provides a more pleasant user experience.

- API enables developers to be more productive and time-efficient by reusing code in complex but repetitive processes. They don't have to start from scratch because the API comes in a detailed JavaScript Object Notation(JSON) format.

## Types of API

- **Open or Public API **: This API is open to developers and other users with few restrictions. It may need registration via an API key or OAuth(Open Authorization), as in the case of the Facebook and Twitter APIs, or it may be completely open, as in the case of the [themealdb](https://www.themealdb.com/). 

- **Internal or Private API**: This type of API is intended for internal use within a company. This type of API is used by the company's various internal teams to improve its products and services.

- **Partner API**: They are not publicly accessible and need specific authorization to use, such as payment gateways like PayPal and payU, and services like DHL, Airbnb API, eBays APIs.

- **Composite API**: According to Google, this composite API allows you to combine up to five API calls into a single request, consuming only one or two credits per composite call. This API shortens the round-trip time and allows you to run the API in a single database transaction.

## How do we access the API?

- **Browser**: This method is the most common method of accessing data. Simply put the API address in the browser tab.

**Result**

```
[
 {
 "id": 1,
 "name": "Leanne Graham",
 "username": "Bret",
 "email": "Sincere@april.biz",
 "address": {
 "street": "Kulas Light",
 "suite": "Apt. 556",
 "city": "Gwenborough",
 "zipcode": "92998-3874",
 "geo": {
 "lat": "-37.3159",
 "lng": "81.1496"
 }
 }
]
```
This API was gotten from [JSON placeholder ](https://jsonplaceholder.typicode.com/)

- **PostMan**: This is an API platform for developers to design, build, test, and iterate their APIs [Wikipedia](https://en.wikipedia.org/wiki/Postman_(software)). This software can either be downloaded to your system [Postman](https://www.postman.com/downloads/) or can be a [chrome extension](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en). The Chrome version is depreciated, so I recommend downloading the app instead.

**This is how a postman looks when you open the app.**

![postman looks when you open the app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxb5qeogyued47z1g3p9.png)

In the picture below, place the API address in that GET box (marked in red) to get a response from the server. 

![postman](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0k7dw0a1hsj0zmb6qyck.jpg)

- **Postwoman**: Similar to Postman, this is a free and quick API request builder. It is a low-cost, quick, and visually appealing option. It allows you to create requests faster, saving you development time. The difference between the two is that you do not need to download it; simply open it in your browser [postwoman](https://postwoman.com.cn/)

**How a postwoman looks when you open the app**

![postwoman](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mzvsx5i4sywd3qaxdc4.png)

**Below is how a postwoman looks when you place an API:**

Place the API address in that GET box (marked in red) to get a response from 

![postwoman](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7kp5c3d1a94luwzcztro.jpg)

- **Curl**: It is a great tool for testing Rest API [Curl](https://curl.se/). It allows you to transfer data to and from a server as well as make various types of requests.

To use curl as a window user :
 
 - Download and install [Gitbash](https://git-scm.com/downloads) because it is a better command line for curl than PowerShell.

**Using curl in the command line, you type the* keyword*, then place the URL API address.**

![curl](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwnm7c5bgt897uhq7xcx.png)

**Result**
![response from curl](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ncv7curaqu3a8cpxw6r.png)
- **Wget**: It is a free software package that retrieves contents from the web server. But the best way is still *curl* to me for HTTPS requests. 

**To install and configure wget for Windows:**

1. Download [wget](https://eternallybored.org/misc/wget/) for Windows and install the package.

2. Navigate to your download folder on your CMD(Command line) or copy the wget.exe file into your C:\Windows\System32 folder.

**Open the command prompt (cmd.exe) and run wget to see if it is installed**.
```
wget -v
```
![wget typed in CMD](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ov46s23t1n3i5dpicr66.png)
The picture above shows

wget: missing URL

Usage: wget [OPTION]... [URL]...

This simply means you should put the API URL

![wget response1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q41vgnu8ox3gm315j6v5.png)
**wget saves the data set.**

![wget saves the data set](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25wrcgb9dg268etxrqq1.jpg)
I prefer *Curl*. Most developers want to see the HTTPS response immediately.

- **Other languages:** API can also be accessed using a different programming language, such as Python.

To start using Python HTTPS requests, you need to install it first:

On your command shell, type this:

```
python -m pip install requests
```
Next, type "python" to enter into the Python shell environment.


![Python shell environment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wc8pepspomfv7nmh1vxo.png)


Next, type the*keyword*. 

```
import requests
```


![keyword import request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tot4hm8uiyuh8hmpb0r8.jpg)

Next, type this into the CMD line.
 
```
requests.get("url").json() 
```
**Result**

![response from request made](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1lfzzsfc5e6bu7lxke7.png)


## Conclusion

An API stands for Application Programming Interface. APIs are everywhere, ranging from technology to non-technological fields. They connect (communicate) two things from one point to another, and there are four types of API, as well as different ways to make an API call (HTTP request).

## Resources

These are some resources you might find helpful in your learning:

- [Curl](https://www.youtube.com/watch?v=7XUibDYw4mc)

- [wget](https://www.jcchouinard.com/wget/)

- [Python API](https://realpython.com/api-integration-in-python/)


**Thanks for Reading**

**If you found this article helpful, please  🧡, share it, and comment.**