eli5 – What does an API & HTTP call mean? And what is the difference between both and their significance ?


eli5 – What does an API & HTTP call mean? And what is the difference between both and their significance ?

In: 3

API means “Application Programming Interface”. It’s a way that one program can access functions from another program. For example, when you double click a document file from Explorer, Explore asks Word’s Open function to open and display the file.

HTTP means “HyperText Transfer Protocol”. This is the main method used to access, download, and display webpages in your browser.

An API is a structured way for one program, or part of a program, to communicate with another. The reason we use APIs is so that one program can change without having to update the other: all program A has to do is make sure its API stays unchanged, and program B can keep working with it, even if program A’s internals are changed.

A common use for APIs is on a web server – a program that is listening for requests from the web. It’s typical for such APIs to be accessed by accessing some specific web address. For example, for a Reddit bot to post a comment to Reddit, it sends a POST request (a specific type of web request) to reddit.com/api/comment with information in a [particular structured format](https://www.reddit.com/dev/api#POST_api_comment). Reddit’s server knows how to understand this format, and can pass it on to Reddit’s internal logic to create a post. Each of these special addresses is called an *endpoint*, and we say that Reddit’s API *exposes* an endpoint for posting comments.

HTTP is a standard for communicating over the web. It contains a few types of message (GET and POST, for requesting and sending[+possibly requesting] information, are the two most common) in a particular format. In the above Reddit comment API, for example, you send a POST request (i.e., you’re sending information, not just asking for it) that contains, among other things, the content of the comment you want to post.

API is an Application Programming Interface, which is, when you say it in reverse, an interface you can program against in an application.

Say you wish to render a picture of a cat on the screen. You would interact with the display subsystem through its API, where you would make function calls against its API to display pixels in the way you want and where you want on the screen. Or if you want to shoot a gun in a video game, you might make an API call to fire toward position x,y and the internal code for the game would do all the calculations and work to make that happen.

The whole point is to do the work for you, so you can just use various libraries and interact with them through their API to get things done, so you don’t have to write all the low level code yourself.

HTTP is HyperText Transfer Protocol. It is “like” an API, in which you’re interacting with a service (which is a program running in memory and listening on a network port) where that protocol allows you to request web pages, post web pages, delete web pages, pass data back and forth, and such things.

Reddit has an API, which uses something called REST, which uses HTTP calls to interact with the reddit subsystem so you can program tools to programmatically interact with reddit (comment, post, moderate subreddits, etc.) without you having to code all that yourself.

An API is usually thought of more interacting with something on your local machine like a .dll library of code that allows you to use prebuilt code, and HTTP is interacting with a web service to interact remotely.

At a high level, they’re identical in concept, at lower levels, the actual mechanisms are different.

HTTP is just a particular method of communication. Kind of like saying “I’ll use morse code”. It just means “using this way of talking, I’m going to say something”. HTTP is a common way of a computer being able to communicate with a server. That’s all.

An API is just a pre-defined set of things you can say, usually to get some type of reply. So if you were playing chess your API might be [name of piece] [grid name to move to]. Like “Queen to A2”.

Making an API call over HTTP means “I will use HTTP to say something, and what I am going to say is something from our pre-defined list of options”

In our example you would use the communication method of HTTP to make an API call for Chess. You might get back a picture of the board game after the move was made.

An API is like a drive-thru window. You tell the person at the window what you want, and they give you some food in response.

A website is you in that situation, the order you place is the “HTTP Request”, the food they give you back is the “HTTP Response”. You do whatever you want with the response – you can eat the food, throw it, bin it, whatever you want.

A website will make a “HTTP Request (or HTTP call)” to an API, the API will give the website some data as a “HTTP Response”, and the website can do what it wants with that data. Display it to the user, bin it, whatever it wants.