GDSC KIIT
Published in

GDSC KIIT

What the hell is an API ?

Photo by Allie Smith on Unsplash

If you have just begun your journey into web development, you’ve probably heard and read the acronym “API” a lot. It’s short for Application Programming Interface. You hear it in the tutorials, courses, you read it in the articles but still fail to deeply understand what it really means.

Being a righteous web developer you take the trouble to google the term “API”, and Wikipedia gives you this…

An application programming interface is a computing interface exposed by a particular software program, library, operating system or internet service, to allow third parties to use the functionality of that software application.

I mean, that’s a really elegant and accurate textbook definition. But it’s a bit out of grasp for the newbie dev.

The Restaurant Analogy

Photo by Dinesh Ramaswamy on Unsplash

Let’s imagine a restaurant.

Restaurants provide us with food. So if you think about it, the kitchen is essentially the core service that keeps the restaurant running, the Executive Chef manages the kitchen in his/her own ways. All the fellow chefs work together to present the delicacies we demand. We go in as customers, we sit down, and we ask the waiter for a menu, we finalise the dishes and give the order. The waiter takes the order to the kitchen and within some time we have the food on our table.

The waiter here acts as an interface between the customers and the kitchen, a way that customers can communicate with the chefs. If we map this analogy to a software system…

Kitchen is the Service

Customers are the Third Parties that need the Service

The Waiter is the API

API’s are interfaces that expose a particular software system, and allow third parties to use the system without dealing with its internal complexity. It helps present a simple abstraction over a particular system. All that third parties need to care about is making appropriate requests and the API will provide them with the data they need. In a nutshell, that’s what an API is, an interface.

When we create web services, we create interfaces known as HTTP APIs, i.e they are APIs that can communicate via HTTP requests. That’s how the internet works, browsers make HTTP requests to the APIs and we get to use the required services. Google Maps, YouTube, Twitter, Instagram all these services have external APIs that developers can use to embed these services in their products. For example, Uber uses the Google Maps API to implement navigation in their apps.

APIs are not just restricted to the Web, all kinds of software systems have APIs. The Linux Kernel gives a comprehensive API which you can use to create a full operating system on top of the kernel. It usually has functionality like, allocating memory, fetching a partition etc.

Let’s have a look at the implementation.

Building a Simple HTTP API

This is how you would implement the simplest HTTP API in go

Simple HTTP server

If you run this file, a server will constantly listen for requests on the specified port.

$ go run server.go
Starting server on port 3000

Here"/" is what we call an API endpoint. "/" is the default endpoint (the one that’s hit when you don’t mention any while making the request). If we had "/home" as an endpoint, we would be sending requests to http://localhost:3000/home

And then you can make requests via the browser or the terminal.

Browser

If we use the curl command to make the request via the terminal, we would have the request details with the output.

$ curl -i localhost:3000
HTTP/1.1 200 OK
Date: Wed, 18 Mar 2020 07:28:30 GMT
Content-Length: 8
Content-Type: text/plain; charset=utf-8
Hi there

So we just wrote a piece of code that is able to listen to requests and provide us with the necessary information. We built a single endpoint for simplicity sake, developers design the endpoints as per the requirement. You could for example build a flight booking service that did the heavy lifting of requesting data from multiple airlines and then sorted the data according to price, availability etc. and later expose a clean and simple API with a few endpoints so that your front-end react application just puts in source and destination in the request and can just have all the data as a response.

Real world APIs are much complicated with many endpoints, if you look up the documentation on any of the APIs you will find many endpoints that we came make HTTP requests to and get the data we need.

There exist different types of APIs, for example in web dev we have REST APIs and SOAP APIs. Sometimes we use a more hybrid approach depending on the needs of the system we are building.

I hope this cleared up your notion of what exactly is an API. It’s just an interface that helps software systems communicate

Resources and Further Reading

APIs are a vast topic, this article was meant for the beginners, you can have a look at the following links if you have an insatiable curiosity regarding the topic 👻

  1. https://en.wikipedia.org/wiki/Application_programming_interface
  2. Restful Web Services by Leonard Richardson & Sam Ruby
  3. https://www.kernel.org/doc/htmldocs/kernel-api/
  4. https://www.youtube.com/watch?v=s7wmiS2mSXY
  5. https://developers.google.com/apis-explorer
  6. https://en.wikipedia.org/wiki/Remote_procedure_call
  7. https://grpc.io/

Thanks for reading.

Do drop a 👏 if you liked this article.

--

--

--

GDSC KIIT is a student developers club powered by Google Developers to enhance technical and problem-solving mindsets of University students led by Praddyum Verma.

Recommended from Medium

Interfaces as a Universal Pattern and The Serenity Notepad

Pre-commit Check with Shell Script to Avoid Using Certain Words

Solana Season Hackathon@Asia’s Community Quadratic Voting & BUIDL submission has ended — 92 BUIDLs…

Why using libraries in general

BigCommerce Employee Spotlight: Shaun McCormick

Why Nanoservices Might Legitimately Share an S3 Bucket

Top 10 CAT Tools to try in 2022 as a translator

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Junaid Rahim

Junaid Rahim

CSE Undergrad at KIIT. Web Developer at DSC KIIT. Web Technologies. Systems. Machine Learning.

More from Medium

Why I decided to become a web backend developer

CRE-Docker Compose for cron job

Optimize Memory to increase the performance of your Unity game

Google Kickstart with Go