What is API?

1.94K viewsEngineeringOther

What is exactly API and why we call it like that? I am learning web development, and always come across APIs. I would love to learn it through an analogy.

In: Engineering

32 Answers

Anonymous 0 Comments

Application Programming Interface. We can break this down word by word.

An “interface” is where two things come together and interact. Consider, say, a car. In order to drive a common car, you need to fiddle with the mechanisms in the car in just the right way to instruct it on where you want it to go. To allow this, the car is built with things like steering wheels, shift levers, and pedals, designed to be interacted with using your hands and legs. The collection of all these controls can be considered an “interface” between you and the car. The responsibility of building up muscle memory to tickle these controls in just the right ways to make the car do useful things is all yours. But once you have that, you have a very efficient way of controlling the car. As a bonus, since many cars have the exact same or nearly the exact same interface, learning the interface of one car means you can now drive almost all cars.

“Application” in here means exactly what you think it means. A computer program. This is the thing the interface is controlling.

“Programming” is referring to the way you’re supposed to use this interface. You are intended to write a computer program that tickles the controls.

So, an “API” is a set of controls exposed by some computer program. If you tickle the controls in very specific ways, you can control that program. You are intended to do this tickling via a secondary computer program of your own. The responsibility of creating that secondary program is up to you, but once you have it, you can freely control the original program with it.

You mention that you’re learning web development. This probably means you’re interacting with a specific kind of API, a so-called “web API”. To use these kinds of APIs, it is usually the case that you write a computer program that sends web requests to a server somewhere. These web requests are the “tickles” that you are sending to the interface, which lives on the server. When the server gets tickled by a web request formatted in just the right way, it will react to that request in some way. For an example, if your request was asking the server to store a value in its database, it may update its internal database with what you gave it. Or, if your request was asking it to give you a piece of data, it may respond with the result it found.

All of this is happening in a format that is optimized for computers to read. Sometimes it’s also somewhat human-readable (if it’s formatted in, say, JSON or XML), but that’s a secondary concern. The only parties the message should be readable by are the main program being controlled, and your program doing the controlling. Your program can always do extra work to make things human-readable after the fact. This is what basically every web-enabled app does–they are designed to tickle web APIs in the background to fetch and send data, and the results of all that back-and-forth are transformed into fancy graphical UIs designed for humans to use.

You are viewing 1 out of 32 answers, click here to view all answers.