What is API?

635 viewsEngineeringOther

What is exactly API and why we call it like that? I am learning web development, and always come across APIs. I would love to learn it through an analogy.

In: Engineering

32 Answers

Anonymous 0 Comments

An API is like the menu in a restaurant. You pick something off the menu and you get it sent to you. You don’t know what happens in the kitchen, but it gives you the options and sends you what you pick.

And API is the same thing. It tells you how you can interact with a server/ system/ whatever and then sends you the info you pick off the menu (the API ). You don’t know what happens under the hood on their side to get the info, but you pick what you want (endpoint, parameters, etc.) and it sends it to you

Anonymous 0 Comments

An API is like a menu at a restaurant. It says what you can order and the available customizations.

More directly, it’s how the website you write can talk to code written by someone else. It tells you the available functionality and what you need to pass in to get what you want.

Anonymous 0 Comments

It allows you to create, read, update, or delete records from a database (like a spreadsheet) or compositions (views) of those data tables based on a set of criteria that’s passed along with the request. This allows you to interact with a program externally to take data out, put data back in, or manipulate what’s there. For example, look up current weather data for a zip code by sending a request.

Anonymous 0 Comments

Application Programming Interface. A fancy word that describes when one program needs to call another. This happens quite often, and to program you call library features a lot, those are also APIs. So it’s a very natural and common thing that programmers do.

For web code, you have to get the data to display from somewhere. There’s a ton of different ways to implement this and it’s way beyond ELI5 to cover them all. Regardless, if a web-interface shows you the current weather, you use an API to retrieve the weather data and then convert that into a display that your user want (css, javascript etc). This can be a lot more complicated than just weather, but it’s the same principle every time. You need to interact with another program to get/pass data that you then present to your user in a form that make sense to them.

Anonymous 0 Comments

Unlike a user **interface**, which is usually made for actual human users, APIs (application programming **interface**) is usually made for code to use. This code can be companion code of a software, or code external to the API (used by code owned by others).

As an example, we might use Google Search via a web browser, but you might have your own opinionated application that leverages the Google Search API via your application code behind the scenes.

Anonymous 0 Comments

API (application programming interface) is a general term for the instruction manual for communicating with some program. It could be any program from low level stuff on your computer like the operating system to programming languages themselves (aka the compiler) to web hosted services. If you’re looking at “web APIs” then that would be more specifically any service that someone has made accessible via the internet. So a little confusingly people call the web service itself an API, even though technically speaking an API is just the set of instructions for communicating with the web service.

Anonymous 0 Comments

When you use your computer, you use a user interface (UI). Sometimes you type commands into a terminal, and there, you’re using a command-line interface or CLI. When the software you use needs to interact with other software, it uses the application programming interface, or API.

It can be helpful to think of software applications, or computers in general, as users, just like human end-users. When humans are users, they need a UI, or CLI. When a computer, or other software application is the user, it needs an API.

Anonymous 0 Comments

You want to bake a cake, and there is a stack of recipes in a binder, but the binder isn’t yours. You can’t open it and just browse.

You can however ask the binder to give you recipes that fit your purpose. For this consulting the binder gives you an application with standard questions. You fill in the questionnaire and the binder gives you back a bunch of recipes that fit your query. All the recipes have the same format, a template, so you can easily redistribute any recipe that comes out of the binder.

The bits in the middle: the questionnaire you filled in and the standard template for the recipe are the API. You know how the questionnaire looks and the answer template. So you can reuse this over and over because if you now want to make a chicken pot, you need to give this and this info in that form and you will get back a stack of recipes that all are formatted identically.

Anonymous 0 Comments

Lots of folks offering the menu analogy, which is helpful but I think has limitations.

Another way to think of an API is like the contract a service publishes. For example
“if you send a GET request to /users, I will return a list of users” 
“if you want to get the data about a user with id 12345, send a GET request to /users/12345. If user 12345 doesn’t exist, you will receive a 404 not found error”
“If you want to delete user 12345 send a DELETE request to /users/12345”

Like others pointed out, one value here is that you don’t need to know what’s going on under the hood for this to work. It also means that the service maintainer can change how they accomplish the tasks as long as they keep the API the same. This is really powerful – as a maintainer, I can rewrite parts of the code to make it faster, or change the database I store things in, or switch operating systems, etc. As long as I keep the API the same, my users don’t care*

*ok, if I made it a lot slower they’d care

often when people refer to an API, they’re talking about an HTTP API, so you’re making HTTP requests to an HTTP server somewhere, and that server implements the API. That’s not the only kind of API, though – APIs can also refer to system calls in an operating system, for example.

Anonymous 0 Comments

It’s simply the set of functions you use to access someone else’s code, or maybe a separate module in your own code. It gets thrown around and can mean slightly different things in different contexts.

In web development it usually is referring to the interface to a web service running on a server somewhere. Say there’s a service that gives you weather. The API might tell you to send a certain request to the server to get the current temperature, or some other request to get the current precipitation.

If you download a software library it will hopefully have an API telling you how to use it. What functions exist. What data types do they expect.

Or if you’re working on a large code base at work and you want to utilize code maintained by a different team, they might have an API that tells you how to use their code.

It’s discussed so much because it’s important to have a clean, easy to use, and well documented API when you give someone else your code. This makes it easy for them to pick it up and use it.