What is an API? How do we use it in a Web application?

Sudhindra Pai
3 min readAug 27, 2021

Many times you might have seen in the websites, in order to create an account for you or simply to authenticate you, a feature is bring provided “Login/Signup using Google/Facebook/Twitter” Right?

Using the different third-party applications to authenticate you.

Wonder what are these? Those are the APIs to fulfill your requests. In your case, it might be simply creating an account for you on the website or just to authenticate you to log into the website.

Always an API asks what you want (a request) and gives you what you've asked (a response).

In the background, Google/Facebook/other third-party vendors ask you to continue with your existing email account — meaning a request has been sent by you to get your account details, and now an API here handles your request (doing some validations) and now a response will be sent to the website you want to login fulfilling your purpose.

These are known as API (Application Programming Interface). To fulfill your purpose using the APIs, a set of functions are written in the backend source code providing the output (response) whenever a request comes from the user (possibly sometimes by the system).

We know Google as a giant company, who writes lots of code and also provides tons of features. One of the most important features is the Login system, if we developers somehow use this feature, then it’ll be really awesome because Google has already taken care of things like verifying users, authenticity, etc reducing so much of our effort.

We don't have to think of what code they've written, how they've written, all we need to do is just using some pre-defined functions, and some variables, that’s it. JOB done!!

Although Login Feature provided by Google is free to use, while sometimes other features provided by some other vendors cost a little bit. Also, a unique key is provided for the API which is called API KEY, just to monitor the usage by that provider in case of any misuse.

There are a lot of advantages to using APIs and you’ll see the most commonly like in weather app (fetching you details all around the globe), Banking apps (status check of your balance), and in many more applications.

Let's explore an API written by GitHub, showing the user details.

Checkout: https://api.github.com

From the above URL, you can see various fields having an URL for each specifying what response it gives.

For example https://api.github.com/search/users

Oops! you have encountered the “Validation Failed” issue, right? The reason is missing parameters “q={query}”.

There are several components of an API Request in order for it to function. Things like Endpoint, Header, Data, and most importantly METHOD, can be used to build a request.

IN our example, we need to send a “q” parameter which defines either the username or email of a GitHub user to get the response.

Here’s https://api.github.com/search/users?q=sudhee-bsp

So, here you got how an API works, at least what it is. Don't forget to try out more of them. See you. Hope this helps!

In the next article, check out creating a custom API using the javascript framework.

--

--