What is API?
Application Programming Interface: a defined contract that lets one piece of software request data or actions from another without knowing how it works inside.
Definition
API stands for Application Programming Interface. An API is a defined contract that lets one piece of software use another without knowing how it is built internally. It specifies which operations are available, what inputs each one takes, which data formats to use, and what responses or errors to expect. The weather widget on your phone does not run a forecasting model; it calls a weather service's API and renders the JSON that comes back. What is an API in programming, beyond web services? The functions a library exposes (Python's json.loads, the browser's fetch and localStorage), the system calls an operating system offers, and the HTTP endpoints a SaaS product publishes are all APIs. What they share is a boundary: callers depend on the published interface, and the provider is free to change the implementation behind it as long as the contract holds. That is why breaking changes to an API are versioned and announced, while internal refactoring is not. An API call is a single request made through that interface. For a web API it is usually an HTTP request: a method (GET, POST), a URL identifying the resource, headers carrying authentication such as an API key or OAuth token, and optionally a body. The server replies with a status code and a payload, usually JSON. Providers often meter API calls, which is why rate limits and per-call pricing are common. When people ask about the "4 types of API", they usually mean one of two separate classifications. By audience, APIs are public (open to any developer, such as the GitHub REST API), partner (shared with specific business partners under an agreement), internal or private (used only inside one organisation), and composite (bundling several calls into one request, often behind an API gateway). By architectural style or protocol, web APIs are commonly REST, GraphQL, gRPC, or SOAP, with WebSockets and webhooks covering real-time and event-driven cases. Any given API has a value on each axis: an internal gRPC API, or a public REST API.
When to Use API
Use an API whenever another system already owns the data or capability you need: payments, maps, email delivery, authentication, LLM inference. Building against a stable, documented API is almost always cheaper than scraping a website or reimplementing the feature. When you publish an API, treat it as a product: document it (OpenAPI for REST, a schema for GraphQL), version it, and keep backward compatibility, because consumers you cannot see will break if you rename a field. Pick the style to fit the consumer: REST for broad public access and cacheability, GraphQL when clients need flexible field selection across related data, gRPC for low-latency service-to-service calls, and webhooks when consumers need to hear about events instead of asking repeatedly. Do not wrap two modules of the same codebase in a network API just to connect them; a function call is simpler.
API in Practice
- An API call with curl to GitHub's public REST API: curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/vercel/next.js The response is JSON with fields such as full_name, stargazers_count, and default_branch.
- The same call from JavaScript using the browser's Fetch API, which is itself an API the browser exposes: const res = await fetch('https://api.github.com/repos/vercel/next.js'); if (!res.ok) throw new Error(`HTTP ${res.status}`); const repo = await res.json(); console.log(repo.stargazers_count);
- A library API: Python's standard library exposes json.loads(text) and json.dumps(obj). You call them by name and signature without reading the parser's source; that published signature is the contract.
- An API with an example from a real product: a checkout page's server calls Stripe's API (POST /v1/payment_intents with an amount and currency, authenticated with a secret key), and Stripe later notifies the shop's server of the result through a webhook.
Common Mistakes
- Treating 'API' as a synonym for 'REST endpoint'. Library interfaces, operating system calls, and browser APIs such as the DOM are APIs too.
- Shipping secret API keys in frontend code or mobile apps, where anyone can extract them. Keep secrets on a server and proxy the call.
- Ignoring rate limits and error responses. Handle 429 and 5xx responses with backoff and retries instead of assuming every call succeeds.
- Making breaking changes (renaming fields, changing types, removing endpoints) without versioning, which silently breaks consumers.
- Mixing up the two '4 types' lists: public/partner/internal/composite describes who may use an API; REST/GraphQL/gRPC/SOAP describes how it is built.