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 necesserily) between lower-level and higher-level software. Generally, the main purpose of an API is to spare from the programmer the need to write software from scratch.
For example, one may look at the task of writing "Hello World" on the screen:
- Do it all yourself:
- Draw, on graph paper, the shapes of the letters H, e, l, o, W, r, d.
- Work out a matrix of black and white squares that look like those letters.
- Work out the sequence of electrical pulses that you need to send to the computer screen to draw that matrix. It might be 5 volts for black, 1 volt for white.
- Repeat the sequence every 60th of a second to keep the message displayed, exploiting persistence of vision.
- Use somebody else's program 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, I would have to bring a power station with me to make my toast! Note that there is nothing stopping somebody else coming up with another standard; a UK toaster will not work in the US, just as a program written for Microsoft Windows will not work directly on DOS.
Two general lines of policies exist regarding publishing APIs:
- Some companies guard their APIs jealously. For example, Sony charges a large amount of money before you can even see the SDK documentation 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, PlayStation consoles which are sold at a loss for Sony).
- 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 authorative implementations exist for an API (such as Microsoft Windows for Windows API), there's nothing that prevents the creation of additional implementations. For example, the Windows API can be provided under Linux using software called Wine.
It is generally legal to analyze API implementations in order to produce a compatible one. This technique is called reverse engineering for the purposes of compatibility. 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 his permission.
Examples of APIs are: