Definition
An application programming interface (API) is a contract that specifies how software components call functions, pass parameters and receive results. Callers follow the documented contract without needing to understand the implementation behind it.
How it works
The caller builds a request according to the interface documentation — for an HTTP-based API, that means the method, path, parameters and credentials. The other side processes the request and responds in an agreed data format, most often JSON. The documentation defines the available operations, inputs, outputs and error handling.
Usage
Websites and apps use web APIs to fetch data from services such as weather, payments or maps. Operating systems and libraries also expose capabilities through APIs — for example, the DOM API a browser provides to JavaScript, or file system interfaces.
Related and confusable terms
An SDK bundles libraries, tools and documentation, usually built around one or more APIs to speed up integration. A CLI is an interface for humans typing commands, while an API is an interface for programs to call. Many services offer an API, an SDK and a CLI at the same time.