"Understanding API: A Simple Guide for Everyone"

"Understanding API: A Simple Guide for Everyone"

ยท

3 min read

Application Programming Interface, or API, is a term you may have come across frequently while working on web application projects. Despite its widespread use, many people find it challenging to understand what API actually is. In this blog, I aim to simplify the concept of API and illustrate it with a simple example.

Let's consider a library as an example.

Library

The library has different sections, each containing different books. Each book has its details, including the title, author name, year of publication, and publication name. This is the same format that API follows, with the information presented in JSON format.

Wait! Wait! Wait!, but what is JSON? ๐Ÿค”

what

JSON, or JavaScript Object Notation, is a text-based format used for exchanging data between systems. It uses key-value pairs to represent data, where the keys are strings and the values can be either strings, numbers, booleans, arrays, or other JSON objects.

Here's a JSON file that includes the keys "title", "author", "publish_year", and "publication":

{

"book": {

"title": "The Great Gatsby",

"author": "F. Scott Fitzgerald",

"publish_year": 1925,

"publication": "Charles Scribner's Sons"

}

}

This JSON file represents information about a book and the keys serve as labels for the data, making it easy to access and manipulate. The JSON file can be considered as the API of a library, with the "book" section as the JSON object.

Before getting into the technical part, let's understand the process with the previous example.

Suppose, You (user) go to the library and make a request to the librarian (server) to bring a book you are wishing for. This request is called API call. The librarian (server) will instruct you to the specific section (object) in which that book is present. You'll see all the information related to the book on the cover page like book title, author name, publish year and publication. Now you can use these information as of your need.

Yeeeeaaa!!!๐Ÿฅณ๐Ÿฅณ got it

Technically, To use APIs, you first need to find the API that suits your needs. For instance, if you want to create a weather web app that shows temperature, humidity, and atmospheric pressure, you can use the popular Open Weather Map API. Some APIs require authentication, in which case you'll need to obtain an API key or other credentials from the API provider.

Next, you need to understand the API endpoint, which is the URL where you make an HTTP request to retrieve data or perform an action. Endpoints have specific parameters that need to be included in the request to retrieve the desired data.

Once you have the API endpoint, you can make a request using a programming language or tool such as Python, JavaScript, or Postman. The request should include the endpoint URL, any required parameters, and authentication credentials.

The API will then return a response in a specified format, such as JSON or XML, which you need to parse in order to extract the data you need. This can typically be done using a library or tool in the programming language you are using.

Finally, you can use the data in your application or store it for later use.

Here are two examples that I made projects with APIs:

  • Weather Web App: A weather web application that allows users to search for the weather by place or their current location.

  • Quoting: A random quote generator that displays a different quote and background on every refresh.

In conclusion, we hope this blog has helped you understand the core concept of APIs.

Give it a thumbs up and share it with your friends and on your social media.

To stay in touch, connect with me โœŒ๐Ÿป๐Ÿ˜

Happy learning!

ย