Application Programming Interface (API)
An application programming interface, commonly referred to as an API, is an interface that allows two different applications to 'talk' to each other by exchanging messages across well-defined channels. APIs simplify development by abstracting the finer workings under the external surface and allowing only pre-defined objects and actions.
The most common implementations of APIs is one wherein the relationship between the applications is that of a provider-consumer. Among other things, the API provider must document:
- the kind of calls a consumer can make
- the authentication/authorization to provide with such calls
- the data that can be sent or received
- the format in which to transmit the data
What are the common API types?
- Software libraries and frameworks are a form of API. They provide features abstracted away as functions that can be invoked with and return data. Being written in the same language and running on the same runtime allows data and control to be transferred to and from the library directly.
- The standard libraries that are a part of the language are another form of API decoupled from the language internals for broader interoperability. For example, even languages other than Java that run on the Java Virtual Machine, like Scala, have access to Java's APIs.
- Operating systems provide a set of APIs that applications can leverage for system-level functionality. POSIX, for example, provides APIs that enable applications to run on any POSIX-conformant system. Linux, BSD, UNIX, and even macOS conform to POSIX. So binaries written for one can directly be compiled to run on another.
What are web APIs?
Web APIs are a class of APIs that operate over the internet carried over HyperText Transfer Protocol. These APIs co-opt internet protocols and conventions such as Authorization headers for authentication and request/response bodies for data transfer.
Since the medium of transfer is generally plain-text, data is usually serialized by the sender into XML or JSON and deserialized by the receiver based on the Content-Type header.
These APIs provide fixed, usually versioned, endpoints allowing reading and, optionally, writing data. The newer REST architecture for stateless services has all but replaced the previously favored SOAP architecture.
Web APIs are also the backbone of the microservices architecture where distinct components of a system work independently, exchanging data via interconnected APIs. Using APIs, each service only exposes a few endpoints while neatly abstracting away implementation details from all other components in the system.
Write clean and secure code with DeepSource
Powerful static analysis that takes 5 minutes to set up and helps you fix code health and security problems on every pull request.