You have probably seen the abbreviation API in software documentation and in descriptions of web services. Almost every program you use relies on APIs, and so will the programs you write.
What is API
API stands for Application Programming Interface.
The word "interface" often means a user interface: the screens and buttons through which a person works with a program. An API is an interface between two programs instead.
An API describes how programs can interact with each other. A program makes some of its functions, classes, methods, data structures, or constants available, and other programs use them through the API.
End users don't work with an API directly. Programmers do, when they build it into their applications. A program can call a function through an API without knowing how that function works inside, which saves a lot of development time.
For example, an application for a specific operating system uses that system's API to work with files, windows, or the network, and its developers don't have to learn how the system works internally.
Why we may need API
Here is why programmers use APIs:
- An API gives you ready-made tools. For example, the audio API of an operating system (such as Core Audio on macOS or WASAPI on Windows) lets your application play and record sound, so you don't have to write the low-level audio code yourself.
- APIs connect systems. When a site lets you log in with your Google account, it talks to Google through an API. Online payments work the same way: the shop's site uses the API of a payment service, and that service connects to the bank.
- An API helps keep data secure. Other programs get only what the API exposes, and many APIs return data only after a key or a login.
- Using an existing API is usually cheaper than building the same functionality yourself.
Using API
An API can be part of a network protocol, a software framework, or the set of system calls of an operating system. It is often implemented as a separate library or operating system service.
Here are the main places where you find APIs:
- A library is a set of ready-made code to reuse in your programs, and its API is the way your code calls it. An API may also cover several libraries.
- A framework can be built from several libraries and implement several APIs.
- An operating system API defines how applications work with the system. Most operating systems let programs use their APIs to work with the file system, render graphics, store data, use the network, play audio, and so on.
- A web API is an interface that a web server offers to other applications over the network.
- With remote APIs, a program works with resources on another machine. For example, the Java Database Connectivity (JDBC) API lets a Java program work with many kinds of databases through the same set of functions, and Java Remote Method Invocation (RMI) lets a program call functions that run on another machine as if they were local.
Common tasks
What an API does depends on its area. Developers commonly use APIs to:
- work with documents. For example, the Document Object Model (DOM) lets a script read and change the content and look of a web page.
- work with graphics, video, or audio. In the browser, Canvas and WebGL render 2D and 3D graphics, and the Web Audio API generates and processes sound.
- get data from a server, for example, to show a weather forecast, a map, or exchange rates on a website.
- read data from devices. A navigation app, for example, needs an API that reports the device's location.
- store data for the user. The Web Storage API keeps data on the client side and holds more than cookies can.
Conclusion
An API describes how one program can use another: which functions it can call, what data it sends, and what it gets back.
APIs give you ready-made functionality, connect systems, help keep data secure, and save development time and cost.
Libraries, frameworks, operating systems, and web servers provide APIs, and remote APIs work with resources on other machines.
Developers use APIs to work with documents, graphics, and audio, to get data from servers and devices, and to store data on the client side.