What exactly is the meaning of an API?

api
Derek picture Derek · Sep 16, 2011 · Viewed 332.1k times · Source

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?

Answer

user166390 picture user166390 · Sep 16, 2011

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.