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.
| Element | Question it answers | Example |
|---|---|---|
| Operations | What can be requested | Create order, list invoices |
| Inputs | Which parameters and formats are accepted | JSON body with customer ID |
| Outputs | What comes back on success | Order object with status field |
| Errors | How failures are reported | HTTP 404, error code and message |
| Authentication | Who may call it | API key, OAuth 2.0 token, JWT |
| Usage limits | How often it may be called | 1,000 requests per minute |
| Versioning policy | How changes are introduced | Version in path, deprecation period |
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.
| Type | Where calls travel | Typical consumers |
|---|---|---|
| Library or framework API | Within one process | Developers using a package or SDK |
| Operating system API | Program to kernel via system calls | Applications needing files, memory, network |
| Private web API | Over a network inside one organization | Internal services and front ends |
| Partner API | Over the internet to approved parties | Contracted businesses with credentials |
| Public API | Over the internet to registered developers | Third-party applications and integrations |
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.
| Style | Interaction model | Strength | Limitation |
|---|---|---|---|
| REST | Resources addressed by URLs and HTTP methods | Simple, cache-friendly, widely understood | Over-fetching or many round trips |
| GraphQL | Client queries exactly the fields it needs | Flexible data retrieval in one request | Harder caching and cost control |
| gRPC | Remote procedure calls over HTTP/2 with Protocol Buffers | Compact, fast, strongly typed | Limited direct browser support |
| SOAP | XML envelopes with formal WSDL contracts | Mature enterprise standards | Verbose and heavyweight |
| Webhooks | Provider pushes events to a consumer URL | No polling needed | Consumer must expose an endpoint |
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.
| Mistake | Symptom | Remedy |
|---|---|---|
| Breaking changes without a new version | Client applications fail after a release | Semantic versioning and deprecation notices |
| Exposing internal database structure | Every schema change ripples to consumers | Design resources around use cases |
| Missing rate limits | One client degrades service for all | Quotas and HTTP 429 responses |
| Secrets in client-side code | Leaked API keys and unauthorized use | Server-side calls and token scopes |
| Outdated documentation | Integrations built on wrong assumptions | Generate docs from the specification |
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.