171

I've searched for the definition of an API in a programming language and I am still finding it hard to understand.

Could anyone advice me in simple, layman's terms:

  1. What is an API?
  2. How is it used?
  3. When and where is it used?
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Derek
  • 2,185
  • 4
  • 20
  • 24
  • 7
    Did you try FOLDOC first? http://foldoc.org/API Their definition _seemed_ fairly "layman" to me. – Ray Toal Sep 16 '11 at 05:17
  • @pst I would have taken it for granted that the OP already looked at Wikipedia because who doesn't check Wikipedia? Misplaced sarcasm on the possibility of using FOLDOC's 1995 definition before checking Wikipedia. Should I delete the comment? – Ray Toal Sep 16 '11 at 06:00
  • If you're looking for a layman explanation, try: http://welcometosoftware.com/what-is-an-api (disclaimer: I wrote it) – Sam Malayek Mar 06 '20 at 00:58

13 Answers13

139

Searches should include Wikipedia, which is surprisingly good for a number of programming concepts/terms such as Application Programming Interface:

What is an API?

An application programming interface (API) is a particular set of rules ('code') and specifications that software programs can follow to communicate with each other. It serves as an interface between different software programs and facilitates their interaction, similar to the way the user interface facilitates interaction between humans and computers.

How is it used?

The same way any set of rules are used.

When and where is it used?

Depends upon realm and API, naturally. Consider these:

  1. The x86 (IA-32) Instruction Set (very useful ;-)
  2. A BIOS interrupt call
  3. OpenGL which is often exposed as a C library
  4. Core Windows system calls: WinAPI
  5. The Classes and Methods in Ruby's core library
  6. The Document Object Model exposed by browsers to JavaScript
  7. Web services, such as those provided by Facebook's Graph API
  8. An implementation of a protocol such as JNI in Java

Happy coding.

  • 5
    +1 on calling out "suprisingly good". For computing, Wikipedia is tops. Some may remember the Wikipedia vs Britannica comparison by Nature: '''According to the Wall Street Journal: "[Wales] says he was glad Nature chose to compare science-related themes 'because on history and the social sciences, we're much weaker.' In other areas - including computer science and the history of 'Star Trek,' he says - Wikipedia is 'way better.'"''' (from http://www.dailybarometer.com/forum/the-tough-position-of-wikipedia-1.2372886) – Ray Toal Sep 16 '11 at 06:21
  • 2
    @user166390 wikipedia entry on api is now pretty bad...I write apis and that entry actually confused me. good thing you quoted what you did, as it has somehow gotten much worse apparently. – eric Dec 30 '14 at 14:37
  • I want to ask is the php file that is put into the url of an ajax request an API?or maybe the ajax request itself is an API already? – Brownman Revival Mar 20 '15 at 02:40
  • Are API's also used for the Internet of Things? Or how do IoT devices send and receieve data? – Pathros May 05 '18 at 14:15
63

An API is the interface through which you access someone elses code or through which someone else's code accesses yours. In effect the public methods and properties.

Klee
  • 2,022
  • 3
  • 23
  • 32
53

Well, in addition to all the answers, I am just adding an example.

As others said API stands for Application Programming Interface through which softwares can interact with each other. Note, not a human interaction.

Where it is used

An example: You are buying an item online through your credit card. You will provide credit card details and press 'continue' button. It will tell you whether your information is correct or not. To provide these results, there are lot of things in the background.

The application will send your credit card details to a remote application which will validate your information and send the result back to your application. API is used in this scenario.

I hope it helps for the beginners who don't understand really what API is.

ANOTHER EXAMPLE

Weather application

Without API - Weather application must open weather.com site and read the details as a human does.

With API - Weather application will send a message to weather.com and receive the result and then display it.

SOURCE - Various online resources

Community
  • 1
  • 1
Gibbs
  • 21,904
  • 13
  • 74
  • 138
  • 3
    Clearly explained with daily example Thanku so much will be helpfull to freshers like me – sai Jul 21 '16 at 07:55
  • so in this case the API is the weather.com that send the data on my reques? or the API is my app that send the requests, receive the data and displays it some way? or the API is the relation of both the weather.com and my app? – Paweł Apr 26 '17 at 10:05
  • 1
    @Paweł API will be the application which requests data – Gibbs Apr 26 '17 at 11:00
  • @Paweł Think of it this way: There are two interface for an app. First, the UI (interface) for a human user. Second, is the API (interface) for another application program. Thus, the API between the weather application and weather.com is weather.com. – vpibano May 30 '17 at 03:42
48

1) What is an API?

API is a contract. A promise to perform described services when asked in specific ways.

2) How is it used?

According to the rules specified in the contract. The whole point of an API is to define how it's used.

3) When and where is it used?

It's used when 2 or more separate systems need to work together to achieve something they can't do alone.

Agent_L
  • 4,960
  • 28
  • 30
16
  1. an API(Application Programming Interface) is a set of defined functions and methods for interfacing with the underlying operating system or another program or service running on the computer.

  2. It is usually used by establishing a reference to a library in your software or importing a function from a dll.

  3. It is used in one form or another in almost all software, being explicitly called in your program or implicitly called by the compiler.

itzmukeshy7
  • 2,669
  • 1
  • 21
  • 29
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
10

API stands for Application Programming Interface, i.e. API is the way for an application to interact with certain system/application/library/etc.

For example, there are API's for OS (WinAPI), API's for other applications (like databases) and for specific libraries (for example, image processing), etc.

APIs are usually developed in a form consumable by a client application. For C/C++ applications, it a set header files and dynamic/static libraries. For Java - set of jars. And so on.

martieva
  • 131
  • 2
  • 11
pupssman
  • 541
  • 2
  • 11
7

It is a set of software components that interact with one another. It provides a set of functions, variables, and object classes for the creation of an application, operating system or any other thing.

jerry
  • 2,581
  • 1
  • 21
  • 32
7

Conaider this situation:

Mark and Lisa are secretly a couple, and because of age difference they are not allowed to be together. Mark and Lisa meet every night when nobody is watching. They have estabilished their own set of rules how to comunicate when the time comes. He stands in her garden and throws the small rock at her window. Lisa knows that it is time, and responds by waving from the window and opening it afterwards so Mark can climb in. That was example how the API works. The rock is initial request to another end. Another end waves, opens the window which basicaly means "Welcome in!".

API is almost like human language but for computers.

xZero
  • 645
  • 2
  • 9
  • 24
6

In layman's terms, I've always said an API is like a translator between two people who speak different languages. In software, data can be consumed or distributed using an API (or translator) so that two different kinds of software can communicate. Good software has a strong translator (API) that follows rules and protocols for security and data cleanliness.

I"m a Marketer, not a coder. This all might not be quite right, but it's what I"ve tried to express for about 10 years now...

Colleen
  • 61
  • 1
  • 1
5

An API is a set of commands, functions, and protocols which programmers can use when building software for a specific OS or any other software. The API allows programmers to use predefined functions to interact with the operating system, instead of writing them from scratch. All computer operating systems, such as Windows, Unix, and the Mac OS and language such as Java provide an application program interface for programmers.

Source

3

An API defines the interfaces by which one piece of software communicates with another at the source level. It provides abstraction by providing a standard set of interfaces - usually functions - that one piece of software (typically a higher-level piece) can invoke from another piece of software (usually a lower-level piece).

For example, an API might abstract the concept of drawing text on the screen through a family of functions that provide everything needed to draw the text. The API merely defines the interface; the piece of software that actually provides the API is known as the implementation of the API.

It is common to call an API a "contract". This is not correct, at least in the legal sense of the term, as an API is not a two-way agreement. The API user (generally, the higher-level software) has zero input into the API and its implementation. It may use the API as-is, or not use it at all: take it or leave it!

A real-world example of an API is the interfaces defined by the C standard and implemented by the standard C library. This API defines a family of basic and essential functions, such as memory management and string manipulation routines.

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
0

Lets say you are developing a game and you want the game user to login their facebook profile(to get your profile information) before playing it,so how your game is going to access facebook? Now here comes the API.Facebook has already written the program(API) for you to do it, you have to just use those programs in your game application.using Facebook-API you can use their services in your application.Here is a good and detailed look on API... http://money.howstuffworks.com/business-communications/how-to-leverage-an-api-for-conferencing1.htm

  • 3
    And You didn't actually say **WHAT** is it... :} And it's more not like a program, but just an interface. The way of dealing with some program. – Kamiccolo Aug 28 '14 at 09:38
-1

Application program interface (API) is a set of routines, protocols, and tools for building software applications. An API specifies how software components should interact and APIs are used when programming graphical user interface (GUI) components. A good API makes it easier to develop a program by providing all the building blocks. A programmer then puts the blocks together.

source: http://www.webopedia.com/TERM/A/API.html