What is API?

475 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.

Anonymous 0 Comments

The menu analogy is closer to the documentation for an API.

It might be easier to think of a more practical example like a smart light bulb. In this case, we’re talking about the types of bulbs that you can control with a phone app or smart speaker.

This light bulb is going to have a set of commands you can send to it. For the sake of this example, we’re going to skip over the part of how to connect to the bulb via Wi-Fi, Bluetooth or whatever proprietary radio system it uses. That’s all a discussion for a different question.

You could send “Set_Power(on)” to turn it on or “Set_Power(off)” to turn it off. You could also send stuff like “Set_Color(red)” or “Set_Brightness(50)” to change color and brightness, respectively.

It’s also possible to send commands that get information back. So something like “Get_Power()” would get it to respond whether or not it’s on. Similarly, you could also run “Get_Color()” or “Get_Brightness()” and get the respective statuses. If the smart bulb is especially smart, it may even support commands like “Get_Power_Usage()” that might return a whole table of dates, times and power consumption.

That set of commands and the responses they can create is the API for this light bulb.

If you wanted to write a program to control the bulb yourself, the API would be the vocabulary your program could use to talk to or listen to the smart bulb.

Anonymous 0 Comments

An API is the middle man between you and something to which you should not have full access. Take for example a bank teller, you ask them for money, THEY go in the back and bring it. Or you go to the armoury and ask the armourer for your gun, HE will hand you the allowed gun/ammo. This is used for data protection.

Anonymous 0 Comments

In simple terms an API is just a way to send and receive data. You can send a request to the API and it’ll either handle storing some data for you or sending some back, usually in a structured format like JSON you can parse and display on your page

Anonymous 0 Comments

Easiest way to describe it would be a moddable video game.

If a game is made, it is compiled, so all of its code is invisible and assets are usually packed so you don’t have loose files you could access and change. Thing of the game as whole, closed thing.

But if game developers had modders in mind, then game might have open ends, for example, a level or item editor, that has access into the “whole” of the game and can change something inside the “whole”. So the whole has some doors you can access and change inner workings somehow.

That’s sort of what APIs are – programs/databases with accessible doors so you could get information out of them.

Even simpler example would be city power grid, which you can access via wall outlets. While you can’t change anything major in the grid, you can access it still.

Anonymous 0 Comments

API are web pages for computers. When you a human load up a website, it has menu, layout, big pictures, all with the goal of making it easy for a human to navigate through its information using eyes and hands on a pointing device. Computers don’t usually have eyes and hands with pointing devices. Instead it can speak a instruction in very specific way, like “Get User with ID 123” and API will respond in very specific ways as well that’s makes it easy for computers to understand the response.

Anonymous 0 Comments

APIs are one way computers share data.   

Take a finance website. If you, a human, browse to 

https://finance.yahoo.com/quote/GOOG

you get a human friendly HTML response with words, charts, colors etc showing you all you want to know about Google stock.  

 Now if you are a computer or a program some developer like yourself wrote and you need that same data, you don’t want pretty formatted text and pictures and stuff targeted for humans (HTML). You want the same info but presented in a way that is easier for a computer program to digest. 

Usually in JSON format.  Like this 

https://query1.finance.yahoo.com/v8/finance/chart/goog

Anonymous 0 Comments

This is not an analogy, because sometimes it helps to be concrete.

You know commands that let you request data from your website? It looks something like this:

                response = fetch(some_url);   // or:         an_image_object = giveMeAFile(“cat.jpeg”);

API means Application Programming Interface – programs talking to other programs.

It turns out, you can also request data from other websites, if they are configured that way. Sometimes these servers don’t even serve html to browsers, but only data for programs that request it. A browser uses HTTP to request HTML, but there is nothing that prevents non-browser-applications from requesting non-html-data.

            weather_data_response = fetch(“www.example-weather-api.com/give-me-weather”);

            console.log(“Today’s weather: ” + weather_data_response.json);

Reddit had some issues with it’s API in the past. I think it was free and they now charge for it. That means that you pay for an API-key, like a username and then you send the key as part of the request, otherwise you don’t get a response.The Reddit API let’s you receive post-data or send new posts programmatically, so you can develop your own app or a bot.

There are also APIs that have nothing to do with the web. You might have a device that can be controlled with software commands. The line between an API and a “library” or a “framework” are blurry. Something can be both an API and a library. I’d say you have an API whenever there are distinct software components talking to each other.

Anonymous 0 Comments

Let’s say you wrote a program. Now you want other programs to be able to use your program. This is achieved by you writing/providing an API to your program. How much or how little the other programs can interact with your program is determined by the API.

Anonymous 0 Comments

I wouldn’t ELI5 this. If you want to be a webdev you should learn this in the following order:

Networking (TCP/IP, UDP, HTTP, DNS) and then something on abstract classes/interfaces and then you should be equipped to understanding this topic quite intuitively.

Analogies are confusing in this sort of environment, and web APIs are really closest to abstract interfaces which get implemented by classes.

ELI5 attempt: An Interface is a contract to deliver a certain thing when requested a certain way. It’s a sort of menu that says “if you provide me with these inputs, I’ll return this as an output”. When we talk about Web APIs, we’re talking about menus that you order from over HTTP. You pass data in, in a way the API expects, it processes it and then sends you back new data. It’s sort of like ordering a pizza between software applications.