An Application Programming Interface (API) is a set of definitions of the ways in which one piece of computer software communicates with another. It is a method of achieving abstraction, usually (but not necessarily) between lower-level and higher-level software. One of the primary purposes of an API is to provide a set of commonly-used functions—for example, to draw windows or icons on the screen. Programmers can then take advantage of the API by making use of its functionality, saving them the task of programming everything from scratch. APIs themselves are abstract: software which provides a certain API is often called the implementation of that API.
- Do it all yourself:
- Draw, on graph paper, the shapes of the letters H, e, l, l, o, W, o, r, l, d.
- Work out a matrix of black and white squares that look like those letters.
- Devise a way to program the CPU to put this matrix into the display adapter's frame buffer.
- Set the graphics card up to scan its frame buffer to generate the correct signal.
- Use an operating system to do some of the work:
- Use an application program (which uses an operating system) to do all this hard work:
APIs are as essential to computers as electrical standards are to the home. One can plug his toaster into the wall whether he is at home or at a neighbour's house, because both houses conform to the standard API for an electrical socket. If there wasn't an API standard, one would have to bring a power station along in order to make toast! Note that there is nothing stopping somebody else coming up with another standard; a European toaster will not work in the US without a transformer, just as a program written for Microsoft Windows will not work directly on a UNIX system without an intermediate API adapter.
There are various design models for APIs. Interfaces intended for the fastest execution often consist of sets of functions, procedures, variables and data structures. However other models exist as well, such as the interpreter used to evaluate expressions in ECMAScript. A good API is able to provide a "black box" or abstraction layer, which prevents the programmer from needing to know how the functions of the API relate to the lower levels of abstraction. This makes it possible to redesign or improve the functions within the API without breaking code that relies on it.
Two general lines of policies exist regarding publishing APIs:
- Some companies guard their APIs jealously. For example, Sony only makes its official API available to licensed developers for its PlayStation. This is because Sony wants to restrict the amount of people who are able to write a PlayStation game, and to profit from them as much as possible. This is typical of companies who do not profit from the sale of API implementations (in this case, Sony breaks even selling PlayStation consoles and takes a loss on marketing, intending to make it up through game royalties created by API licensing).
- Other companies propagate their APIs freely. For example, Microsoft deliberately makes their API information public, so that software will be written for the Windows platform. The sale of the third-party software sells copies of Windows. This is typical of companies who profit from the sale of API implementations (in this case, Microsoft Windows, which is sold at a gain for Microsoft).
An API which does not require royalties for access and usage is called "open". The APIs provided by Free software (such as software distributed under the GNU General Public License), are open by definition, since anyone can look into the source of the software and figure out the API. Although usually authoritative "reference implementations" exist for an API (such as Microsoft Windows for the Win32 API), there's nothing that prevents the creation of additional implementations. For example, most of the Win32 API can be provided under a UNIX system using software called WINE.
It is generally lawful to analyze API implementations in order to produce a compatible one. This technique is called reverse engineering for the purposes of interoperability. However, the legal situation is often ambiguous, so that care and legal counsel should be taken before the reverse engineering is carried out. For example, while APIs usually do not have an obvious legal status, they may include patents that may not be used until the patent holder gives permission.
Examples of APIs are:
- The PC BIOS call interface
- Document Object Models of various applications, such as HTML
- The Single UNIX Specification
- The Microsoft Win32 API
- The J2EE Java 2 Enterprise Edition APIs
- ASPI for SCSI device interfacing
- The Carbon APIs for the Macintosh OS
- Simple Network Management Protocol (SNMP)
- Universal Plug and Play (UPNP)
- Common Object Request Broker Architecture (CORBA)