What the heck is an API?

Application Program Interfaces (APIs) were a really hard concept for me to wrap my head around when I first started learning. They were always mentioned in blog posts and tutorials, but no one ever really explained what they actually were.

It was when I was in Greece that I finally understood what they did. My friend and I were walking around and trying to get a hamburger (we were homesick) and we could not find one. Eventually, my friend got out his phone, typed in “where can I get a hamburger?” and then used Google Translate to show it to someone in a store that we were passing. That’s when it hit me. Google translate WAS our API. I’ll explain. (We found hamburgers by the way):

An API is basically a translator from program to program. Say that you’re writing the backend of your application in Python and the front end in JavaScript. You would code translations for certain functions into your back end that tell it what to do when your front end calls it.

Imagine that you’re going on a trip to Mexico. You’re not going for very long, but you know that you’re going to want a cheeseburger, a beer, and (inevitably) a bathroom. You take out your phone and make a program that says, “If I say ‘I want a cheeseburger’” you say, “quiero una hamburguesa con queso”. That is an API call. It bridges the gap between two languages to convey a certain function.

There are many built-in APIs. If you’re doing web development you may be familiar with the document object model (DOM). Whenever you are coding anything that would interact with the window or HTML you are using the browser’s built-in translator to tell your JavaScript to tell the browser what to do.

If you think about an API this way I believe that it will help you in understanding how to manipulate the DOM as well as HTTP calls to your servers. Just think that you are creating a translator.