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
2
u/tobysmith568 Mar 26 '20
From the context in your description, I assume you're asking about web APIs.
Simply, web APIs allow your program to get information which it does not otherwise have.
So let's say that you're making an application to display the current weather - how would you get the information to display in your app? You would use a weather web API.
An example could be this one:
https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22
Notice that the URL there contains a few variables, firstly it's asking for version 2.5 of the API. Secondly q = London, UK - so this request is asking about London. Finally, appid = an ID.
Web APIs usually require some type of ID to be passed in some manner, this is to protect them. Think of your ID as your username and password rolled into one. Don't worry, what I typed there isn't my ID - it's just a sample one given by openweathermap.org
Finally, if you go to that URL yourself, you can see the data. It doesn't look like a normal website, it only returns data in a specific plaintext format - in this case, JSON.
Now, in the weather app that you're making you can visit that specific, custom URL, download the JSON, and then use the data within it.
Web APIs are not only for getting data like we've spoken about here, you can also send data to a server, request a server to delete data, and more - it just depends on how the web API is written.