API

Also known as: Application programming interface

On this page 7

An API (application programming interface) is a defined contract between software components that specifies how one component can request operations or data from another, without needing to know how the other component is built internally. In programming, APIs are the boundaries between libraries, operating systems, services and applications: they state which calls exist, what inputs they accept, what outputs and errors they return and which rules govern their use.

The idea covers far more than web services. A function library, a database driver, a browser feature and a cloud platform all expose APIs, and the study of APIs, from REST API design to versioning and rate limiting, concerns how to keep these boundaries stable, understandable and secure.

How an API separates interface from implementation

The central principle of an API is abstraction through a stable interface. The provider publishes what can be called and what each call guarantees, while keeping the implementation private. The consumer depends only on that published surface, so the provider can rewrite internals, change databases or scale servers without breaking existing clients, as long as the contract holds.

A complete API contract normally describes several elements. The table below lists them and the question each one answers for a developer.

ElementQuestion it answersExample
OperationsWhat can be requestedCreate order, list invoices
InputsWhich parameters and formats are acceptedJSON body with customer ID
OutputsWhat comes back on successOrder object with status field
ErrorsHow failures are reportedHTTP 404, error code and message
AuthenticationWho may call itAPI key, OAuth 2.0 token, JWT
Usage limitsHow often it may be called1,000 requests per minute
Versioning policyHow changes are introducedVersion in path, deprecation period
Elements of an API contract

Machine-readable descriptions such as the OpenAPI Specification for HTTP services or AsyncAPI for event-driven systems turn this contract into a file that tools can validate, generate documentation from and use to produce client code.

Kinds of APIs by scope and audience

APIs are commonly grouped by where they run and who may use them. A local library API is called inside the same process, while a remote API crosses a network, which adds latency, partial failure and security concerns that a local call never faces.

TypeWhere calls travelTypical consumers
Library or framework APIWithin one processDevelopers using a package or SDK
Operating system APIProgram to kernel via system callsApplications needing files, memory, network
Private web APIOver a network inside one organizationInternal services and front ends
Partner APIOver the internet to approved partiesContracted businesses with credentials
Public APIOver the internet to registered developersThird-party applications and integrations
API types by scope

The audience shapes design priorities. A private API can change quickly because all consumers are known, whereas a public API must treat backward compatibility as a promise, since unknown clients may depend on every documented field.

API styles and protocols compared

Remote APIs follow different architectural styles, each with its own model of how requests are expressed. Choosing among them is a trade-off between simplicity, efficiency, flexibility and tooling, so no style is universally superior.

StyleInteraction modelStrengthLimitation
RESTResources addressed by URLs and HTTP methodsSimple, cache-friendly, widely understoodOver-fetching or many round trips
GraphQLClient queries exactly the fields it needsFlexible data retrieval in one requestHarder caching and cost control
gRPCRemote procedure calls over HTTP/2 with Protocol BuffersCompact, fast, strongly typedLimited direct browser support
SOAPXML envelopes with formal WSDL contractsMature enterprise standardsVerbose and heavyweight
WebhooksProvider pushes events to a consumer URLNo polling neededConsumer must expose an endpoint
Common remote API styles

In practice, many systems combine styles: a public REST API for broad compatibility, gRPC between internal services for efficiency and webhooks to notify partners of events.

Designing and operating a reliable API

Good API design starts from the consumer’s tasks rather than from the internal data model. Consistent naming, predictable error formats and clear documentation reduce integration time more than any single technology choice. An API-first approach writes and reviews the contract before implementation begins.

Operation adds a second set of duties. An API gateway often centralizes authentication, rate limiting and logging, while pagination keeps large result sets manageable. Idempotency keys allow clients to retry a failed payment or order request without creating duplicates, which is essential on unreliable networks.

  • Version deliberately: add fields freely, but remove or rename them only in a new version with a published deprecation period.
  • Return meaningful errors: a machine-readable code plus a human-readable message speeds up debugging.
  • Secure every endpoint: use TLS, short-lived tokens and the principle of least privilege.
  • Measure usage: latency, error rates and per-client volume reveal problems before consumers report them.

Common API mistakes and their consequences

Most API failures are contract failures rather than code failures. The table below links frequent mistakes to their symptoms and the usual remedy.

MistakeSymptomRemedy
Breaking changes without a new versionClient applications fail after a releaseSemantic versioning and deprecation notices
Exposing internal database structureEvery schema change ripples to consumersDesign resources around use cases
Missing rate limitsOne client degrades service for allQuotas and HTTP 429 responses
Secrets in client-side codeLeaked API keys and unauthorized useServer-side calls and token scopes
Outdated documentationIntegrations built on wrong assumptionsGenerate docs from the specification
Frequent API mistakes

In simple terms

An API is like the menu and the waiter in a restaurant. The menu lists what can be ordered and how. The waiter takes the order to the kitchen and brings back the dish. The guest never needs to know how the kitchen works.

Software works the same way. One program asks another for something, such as the weather for a city or the status of a parcel, using an agreed list of requests and answers. As long as both sides keep to that agreement, each can change its own inner workings freely.

A practical example

An online shop wants to show customers the live delivery status of their parcels. Instead of building its own tracking network, the shop’s developers integrate the carrier’s public REST API. They register for an API key, read the OpenAPI description and write a small service that calls the tracking endpoint with each parcel number.

The carrier allows 600 requests per minute, so the shop caches responses for five minutes and subscribes to the carrier’s webhook for status changes instead of polling every parcel repeatedly. When the carrier later releases version 2 of its API with a new address format, version 1 keeps working during a twelve-month deprecation period, giving the shop time to migrate.

The result is a tracking page that updates within minutes of each scan, built in about two weeks, with no dependency on the carrier’s internal systems beyond the published contract.