Sign in
Log inSign up

Introduction to the concept of APIs

Maureen Anyanwu's photo
Maureen Anyanwu
·Apr 25, 2021·

4 min read

Introduction to the concept of APIs

What exactly are APIs ?

API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. Imagine typing out a word or sentence on the google page search bar, immediately you press enter, search results gets displayed to you as a user. Under the hood, your search input is sent to the backend via the API which connects your search input to the store of information at the backend and searches for results that match your input. This data is then received, converted and displayed for the user to see. This whole process occurs within a twinkle of an eye( provided you have a stable data connection). The API links the frontend side of that page to the backend serving as a form of communication link between the two sides. Let’s break this down further: waiter in a restaurant

Imagine being in a standard restaurant and trying to order food. You would not see the kitchen or the processes involved in making that food but when you place an order, your food gets delivered to you. You only get to see the food but not the processes involved. The waiters then just deliver the food to you in a way that is appreciated and recognized by the consumer. Notice how there’s a communication or interaction between the waiter who you placed an order and the kitchen servers who make the food and send them back to the waiters that get them delivered to you. The API can be likened to these waiters. They serve as a link between the consumer and the kitchen servers. They relay your message to the kitchen servers who then prepare and make the food then the waiters collect this food and presents them to you. That is what an API does. Basically, an API sends information to the server and then sends back the server response to the user. This sums up the whole interaction process occurring in applications

Now imagine if there were no waiters and every customer had to go make their own food in the kitchen and then serve themselves or go tell the kitchen servers what they wanted, it can overwhelm the servers as a lot of people are coming to them at the same time and there might be confusion or mistakes in the end results whereby they deliver a meal meant for another person to you. But where a waiter is designated to you to handle your order, orderliness is ensured. Like APIs, to make a request to the server, there are specific endpoints that must be called to access a particular information or enjoy a certain functionality. In API Terminology, an API Endpoint refers to a service provider that provides a specific subset of functions within the same Interface.

How to use APIs

As a Frontend Developer, APIs can be integrated into your application using some inbuilt objects and open source libraries like “axios” or using “fetch” in the case of JavaScript.

Before using an API, it would save more time if you read the documentation attached to it as it will help you while making requests to the endpoints. The documentation tells you all the necessary information regarding making api calls in your application. It tells you if a certain request requires a token or form of authorization before a response can be sent.

There are four types of actions an API can take:

  • GET: requests data from a server — can be status or specifics (like last_name)
  • POST: sends changes from the client to the server; think of this as adding information to the server, like making a new entry
  • PUT: revises or adds to existing information
  • DELETE: deletes existing information

While making requests to these endpoints, ensure to make the right request to the right endpoint. Imagine that you make an order for a chicken avocado sandwich to a waiter in charge of drinks. You’re definitely not getting any because you made the right request to the wrong waiter. So when you make requests to wrong endpoints, you get an error. Examples of free APIs can be found here. They can be used for different functions like getting weather forecast data, cryptocurrency data, country information and so on. Another example is JSON placeholder which is a free online REST API that you can use whenever you need some fake data for an application.