r/AskProgramming • u/cellwall-999 • Mar 26 '20
APIs Explained ...
I dunno but I don't understand APIs fluently. Does anyone know of an informative article or perhaps a website or just personally explain to me frankly wtf APIs are an why we need them ...
Edit: Thanks everyone for your empathetic contributions. Guess what; I have a better understanding of APIs now than I did before.
53
Upvotes
15
u/frostbyte650 Mar 26 '20 edited Mar 26 '20
API stands for “Application Programming Interface”
Technically, it’s just an abstraction layer of functions that perform programmic tasks.
Most of the time you hear about APIs it’s in relation to web development where there’s a front-end / back-end model. It’s referring to the back-end.
So take reddit for example. Reddit has an API that acts as the controller of data. So you have the front end (either the app or reddit.com) & when you first open the app or webpage, your device sends a request to Reddit’s API saying “hey, can I get the 20 hottest posts from r/askprogramming” and the reddit API will be like “sure, here you go!” And it sends your device the 20 hottest posts in the form of raw data containing text & your device will display that data however the front-end was designed to. Same goes for posting data, when I hit “send” on this post, my phone will send a request to Reddit’s API and be like “hey! This user replied to this post with this text” and the API will be like “thanks! I’ll add this text to the database” so when your device asks the API for all the replies to your post, it’ll send you my text that it stored in the database and your device will display it as a reply.
Generally, any time you need to deal with users modifying data you’ll need to create an API that does the actual managing of that data.
That’s what people generally mean when they refer to an “API” but it can actually refer to any abstracted programming layer.
Like, your computer itself also has an API that your applications use to manipulate states. So for example when you download something from a website, generally the way it works is your browser will request the file from the web server & then it will tell your computer’s API “hey, here’s this file I got, I need you to save it” and your computer will be like “No problem!” And then it’ll take the file and encode the data to your hard drive & thanks to this abstraction model, the browser developers only need to code one “save function” and your computer will write it to the drive using whatever method it needs to and the browser developer doesn’t need to care whether the computer has a SSD or HDD because the computer’s API handles that instead.
It’s a very powerful model & if you’ve ever written a program (or even used just a computer) you’ve likely used APIs without even knowing it & that’s kind of their point.
Edit: I just looked through your post history & it seems like you’re trying to learn java, this book is a great resource that starts with the fundamentals of Java & programming concepts like this then gets into how to apply them efficiently as algorithms that manipulate data structures (which you’ll soon find is exactly what all programming is)