Getting started with Application Programming Interface (API)

Getting started with Application Programming Interface (API)

ยท

6 min read

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:

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. 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.

  • 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

  • PostMan: This is an API platform for developers to design, build, test, and iterate their APIs Wikipedia. This software can either be downloaded to your system Postman or can be a chrome extension. The Chrome version is depreciated, so I recommend downloading the app instead.

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

FireShot Capture 193 - Untitled Request - My Workspace - web.postman.co.png

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

InkedFireShot Capture 191 - https___jsonplaceholder.typicode.com_users - My Workspace - web.postman.co.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

How a postwoman looks when you open the app

FireShot Capture 194 - Postwoman โ€ข A free, fast and beautiful API request builder - postwoman.com.cn.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 the server

InkedFireShot Capture 197 - Postwoman โ€ข A free, fast and beautiful API request builder - postwoman.com.cn.jpg

  • Curl: It is a great tool for testing Rest API Curl. 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 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.

Screenshot (48).png

Result

Screenshot (47).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 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

Screenshot (51).png

The picture above shows

wget: missing URL

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

This simply means you should put the API URL

Screenshot (52).png

wget saves the data set.

Screenshot (54).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.

Screenshot (54).png

Next, type thekeyword.

import requests

Screenshot (56).jpg

Next, type this into the CMD line.

requests.get("url").json()

Result

image.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:

Thanks for Reading

If you found this article helpful, please ๐Ÿงก, share it, and comment.

Did you find this article valuable?

Support Cent Blog </๐Ÿ’–> by becoming a sponsor. Any amount is appreciated!

ย