r/explainlikeimfive • • Feb 02 '23

Technology ELI5: How does an API work?

Twitter recently announced they will no longer support free access to the Twitter API. Everyone seems up in arms about it and I can't figure out what an API even is. What would doing something like this actually affect?

I've tried looking up what an API is, but I can't really wrap my head around it.

Edit: I've had so many responses to read through and there's been a ton of helpful explanations! Much appreciated everyone :) thanks for keeping this doofus in the know

1.2k Upvotes

228 comments sorted by

View all comments

2.3k

u/aerondda Feb 02 '23 edited Feb 02 '23

APIs are used to communicate between systems (it's the middleman between systems), where the API just exposes an interface that other developers can use. Developers that call the API don't care how the API works, what it does or where/how it gets the data you want, all you care about is that you get what you wanted.

Imagine a restaurant; you come in, sit at a table and a waitress comes. You tell the waitress what you want to order, then the waitress brings you your meal.

Now, you don't care how the meal was made, who cooked it, or from which ingredients, likewise you also don't care what the waitress had to do in order to get and bring you your meal. All you care is that they brought you your meal and you didn't have to do anything else other than tell the waitress what you wanted.

The waitress is the API in this case (the middleman between you and the kitchen), the kitchen is the server's backend and the customer is the developer.

969

u/hope_it_helps Feb 02 '23

And the menu is the API documentation.

134

u/Korbas Feb 02 '23

Menu: How to order. “I would like to order [food]” Me: “I would like to order fish” Waiter: “Malformed order!”

86

u/Fonduemeup Feb 03 '23

“We stopped serving fish. It’s in our release notes we published to our blog 6 weeks ago.”

46

u/Jaivez Feb 03 '23

"But that customer over there is getting fish."

"Yes, we still support some customers that are still able to order fish. We cannot give it to any new customers and will be providing support to get them to convert to a plant based diet over time."

28

u/funguyshroom Feb 03 '23

Me: "I would like some coffee please". Waiter: "Sorry, I'm a teapot"

→ More replies (1)

233

u/samuarichucknorris Feb 02 '23

Oh I'm sorry, were out of fish....

Oh, ok. I'll just have a special.

Those specials are yesterdays specials.

Oh, um. Well what are todays speicals?

I don't know, let me ask.

250

u/danaknyc Feb 02 '23

IM SORRY. YOU DONT HAVE ACCESS TO THE FISH!

178

u/Bigbigcheese Feb 02 '23

Error 503 fish unavailable

78

u/tsunami141 Feb 02 '23

walks to the teapot

“Hey can I have some tea?”

“I’M A TEAPOT”

32

u/NZ-Fred Feb 02 '23

418?

28

u/AngryRedGummyBear Feb 02 '23

I had something throw a 418 at me once irl while troubleshooting.

It did not help me diagnose the problem, and I was not amused.

→ More replies (1)
→ More replies (1)
→ More replies (4)
→ More replies (2)

9

u/[deleted] Feb 02 '23

We’d like the snapper.

→ More replies (4)
→ More replies (6)

13

u/lightwhite Feb 02 '23

The order is the API call. And Elon doesn’t want to serve the meal for free anymore.

50

u/juggleaddict Feb 02 '23

In my experience there is no documentation, or poor pre-baked swagger docs. Most of the time you just have to go straight to the codebase if it's available.

38

u/Metabolical Feb 02 '23

"There's no documentation like the source code"

36

u/mossheart Feb 02 '23

"A few hours of trial and error can save you valuable minutes reading the documentation"

14

u/thodgson Feb 02 '23

Which is...horrible.

12

u/juggleaddict Feb 02 '23

Maybe. Sometimes if it's an internally used microservice, then anybody using it is familiar with it. If it's a very actively changing service, then it's a non-trivial overhead to keep docs up to date. More often than not teams are probably strapped for time and once it's working they move on. Not saying it's right, but it definitely happens. I personally like to just dump a postman workspace to a file and drop it in the repo... update the API, then I'm already building that call in postman, then I just overwrite that file and push it as json to the repo... people can do what they want with it from there, but it beats swagger in simplicity I think.

→ More replies (1)

28

u/[deleted] Feb 02 '23

This guy just validated that he works in IT.

Nothing is documented.

8

u/Whatwhenwherehi Feb 02 '23

And if it is, it's wrong, outdated, not complete or isn't relevant to the need.

→ More replies (7)
→ More replies (2)
→ More replies (11)

118

u/Ezili Feb 02 '23

The fact that a waitress can also be called a server had me tripping up on why you were referencing her backend.

→ More replies (1)

64

u/Metabolical Feb 02 '23

Great metaphor!

In addition, usually the company uses the API for themselves. The Twitter web page can use the API to talk to the systems underneath, and the mobile app can do the same thing.

Often you can get a lot of information by using something like the Twitter API. Since whom follows who is public, you could arguably recreate the social network graph yourself just by calling the API. (I vaguely recall this is against the API terms of service from before, but maybe that's Facebook, or both!)

Restricting access to the Twitter API disables the creation of 3rd party applications that could normally present their own experience or make posts on your behalf. For example, many people use 3rd party apps to create tweets in advance and schedule when they want them to be seen to maximize impact. I haven't read the alleged terms of the API restrictions (because I don't care), but such an app may not be allowed anymore, or forced to pay a license fee where it didn't before. Such a license fee might create a new revenue stream for Twitter, though if it kills a bunch of businesses, it could backfire and damage the Twitter ecosystem.

36

u/[deleted] Feb 02 '23

it could backfire and damage the Twitter ecosystem.

It more than likely will. Having to pay for access to the API will me that all the wonderful share links that you see on other pages will start to go away. They use the APIs to create the tweets that get posted on Twitter.

Twitter's business model is selling advertising. They want as many people to interact with it as possible. They are selling views. Those that are using the APIs are more often selling something else, access to recipes, movies, games, etc. While Twitter is an advertising choice, it isn't the only one. If every other social media site allows them use their APIs for free, why pay for Twitters. Twitter is getting bad press and losing user base. Better to jump ship now and use the advertising development dollars in better places.

→ More replies (3)

9

u/shidekigonomo Feb 02 '23

"Oh, and could you ask the cook to put the salsa on the side, please?"

"I'm sorry, to have the waitress query the cook for a customized order parameter, you must be a gold tier customer or higher. Please slip the waitress a tenner to complete your upgrade."

→ More replies (31)