What is an API?

Everyone keeps talking about it but it can be confusing for for beginners. So here a simple example!

🧵A thread 🧵

#100DaysOfCode
When you use an API, you're using an interface that lets the program you write control or access a program somebody else wrote.

As an analogy, suppose your program is a robot and you want your robot to get into a car and drive across the city.
When you drive a car, do you care how it works inside?

Do you care what kind of engine the car has? That it's a traditional gas engine, a disel, or a hybrid?

All of those things affect how the car works, but those aren't the interface.
The interface of a car is the steering wheel, gearshift, and pedals - plus all of the other levers and controls to access all of the car's other functions.

So if you were building a robot to control a car, you don't have to teach it how an internal combustion engine works.
You have to teach it how to accelerate, brake, steer, and shift gears, by working those controls.

So now let's relate this back to a programming example.

Twitter has an API.

That means you can write a program that accesses or controls Twitter.
You don't have to know how Twitter works internally. You just have to know their API - the interface for programmers to interact with their service.
Sometimes APIs consist of example code in different languages, sometimes they consist of code that you need to include in your program.

Sometimes they're just documentation that you need to read to learn how to write a program to interact with that particular service.
But they're all the same - in the case of Twitter, it lets you write a program to do things like access someone's most recent tweets, or log into your Twitter account and post a new Tweet.
Most of the major web services like Google, Facebook, Reddit, etc. all have APIs - you can use them to automate almost anything you would do manually.
Original source:
(u/dmazzoni on r/learprogramming)
You can follow @rafrasenberg.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: