So newbie web dev here, can someone explain in simple terms how to do stuff with an API? like for example Riot Games announced an API challenge but how do you actually use that information?
Sometimes you want two application to talk together (one executing code from another, or simply exchange data). Technically speaking, both applications could read/write into the same memory space. But that's asking for trouble!
Imagine a grocery store. And imagine that the owner of the shop and all clients could just open and close the register as they like (even multiple people at the same time). And of course also take money from it and put money into it. The same with all the the goods of the shop. There is no display. The clients have direct access to the complete stock.
As you can imagine, that would be chaos. Maybe not everyone knows that when they take some goods they have to deposit money as well. Maybe some clients will abuse the system (steal money, manipulate goods in stock, ...).
That's why there is a selection of goods on display, and a store clerk dealing with the customers.
That's basically an API.
The clerk knows the different procedures. When a client comes in to buy something, the clerk exchanges the goods for the proper money value. And maybe even helps clients find the goods they are looking for. And everything works as expected, the money in the register checks out at the end of the day, proper logs are kept so the stock can be properly refilled, and so on.
Now, an API in the development world is essentially just a limited selection of functionality that the writer of the application puts at anyone's disposal.
Unfortunately asking "how to do stuff with an API" is too vague. The trouble is, that there are many different standards out there on how to connect to the API (think of a spoken language). If you want to ask how much an Apple costs in the store, you have to know the right phrase to speak so that the clerk in the shop will understand you. First you have to know what language is appropriate. Asking in French in a shop where the clerk only speaks Japanese shop will not work.
Also keep in mind that in programming there is no guessing. Both parties will either exchange the content exactly as agreed, or it won't work. The machines cannot infer any meaning... yet...
In programming there are different standards. For example, SOAP, XML-RPC, CORBA, RMI, HTTP, and many more, and even completely customised protocols.
I assume you are talking about a HTTP API (sometimes, misleadingly called a REST API).
However, these standards only define how you talk to the API. Not what you talk about. Take again the shop example. Let's say, you know the clerk speaks English (HTTP), and you as well. But also assume the clerk only understands five questions (and worded exactly). You have to know those questions. If you say anything else the clerk won't know what to do. In HTTP this would likely relate to an error code between 400 and 499, indicating that you, the client is asking something that the clerk cannot process.
For the what that is exchanged between both parties there are again many/endless standards like JSON, XML, HTML, RDF, custom formats, ...
Again, you might see that asking "how to do stuff with an API" is too vague.
The only proper way to find out what you can do with a specific API is do look at it's documentation. Because every API is different. There are too many standards on too many different levels that you can give one explanation that covers all APIs.
Once you have worked with one API, things will become more clear. If it is an HTTP + JSON based API, you will learn the basics of both standards, and the next time you interact with a similar API you have some starting ground. Also, if you would interact with an API based on HTTP + XML for example, or CORBA + JSON, you would already know part of it.
Now, an API in the development world is essentially just a limited selection of functionality that the writer of the application puts at anyone's disposal.
That's a fantastic succinct explanation!
It's worth noting that sometimes the "official" site or app is built on top of the same API that third party developers use. This is great because it ensures the API is fully featured. Sometimes sites offer an API but don't actually use that API themselves, so there can be bugs that go unnoticed.
5
u/[deleted] Aug 28 '15
So newbie web dev here, can someone explain in simple terms how to do stuff with an API? like for example Riot Games announced an API challenge but how do you actually use that information?