What is an API?
An application programming interface is an agreed way for one piece of software to use another, defining which requests it accepts and what it returns.
What does an API actually define?
A contract. It lists the operations available, the inputs each accepts, the outputs and errors each can produce, and the rules for using them, such as authentication and limits. As long as both sides honour the contract, either can change its internals freely. That separation is why software can be built from parts made by different teams and companies, and why an application can switch database drivers or payment providers without being rewritten.
Which kinds of API exist?
| Kind | Example | How it is called |
|---|---|---|
| Library API | A cryptography or image library | Function calls inside one process |
| Operating system API | Linux system calls, POSIX | System calls from programs to the kernel |
| Hardware interface | NVMe command set | Driver commands to a device |
| Network or web API | A payment or mapping service | Requests over HTTP or other protocols |
In everyday speech "API" usually means the last kind, a service reached over the network, but the idea is the same at every level. You can watch the operating system API at work on any server: strace -c -f curl -s https://example.org -o /dev/null counts every system call curl makes.
How do the main web API styles compare?
| Style | Shape | Strength | Typical use |
|---|---|---|---|
| REST | Resources with URLs, HTTP methods, JSON | Simple, cacheable, universal tooling | Public APIs, web and mobile back ends |
| GraphQL | One endpoint, client chooses fields | Fetch exactly what a screen needs | Complex front ends |
| gRPC | Typed methods over HTTP/2, binary messages | Fast, strict contracts, streaming | Service-to-service calls |
| Webhooks | Server calls your URL when something happens | Push instead of polling | Payments, Git events, notifications |
| WebSocket | Long-lived two-way connection | Real-time updates | Chat, live dashboards, games |
Our REST API article goes deeper into the most common style.
How are API callers identified?
With keys, tokens or certificates. Simple APIs issue a static key per client, sent in a header; more complete ones use OAuth 2.0 to issue short-lived access tokens with limited scopes. Service-to-service calls inside your own systems can use mutual TLS, where both sides present certificates. Whatever the method, keys belong in a secrets store and never in client-side code or public repositories.
Why do APIs have rate limits?
To protect the service and share capacity fairly. Limits per key or address stop one client, buggy or malicious, from exhausting resources for everyone. Good APIs return 429 with a Retry-After header and document their limits. When you run an API, enforce limits at the proxy layer before requests reach the application; NGINX can do it in a few lines:
limit_req_zone $http_x_api_key zone=perkey:20m rate=20r/s;
upstream api_pool { server 127.0.0.1:8300; server 127.0.0.1:8301 backup; }
server {
location /v1/ {
limit_req zone=perkey burst=40 nodelay;
limit_req_status 429;
proxy_pass http://api_pool;
}
}
How do webhooks fit in?
They reverse the direction: instead of your system asking repeatedly whether something changed, the other system calls your URL when it does. Receiving webhooks safely means verifying a signature on each request, responding quickly and doing the real work asynchronously, accepting that the same event can arrive twice, and logging deliveries for troubleshooting. Payment platforms, Git hosts and monitoring tools all rely on them.
What makes an API pleasant to use?
Consistency, documentation and stability. Use the same naming, pagination, error format and authentication across every endpoint; publish a machine-readable description such as OpenAPI with examples; announce breaking changes well ahead and keep old versions running for a stated period. Clear error messages that say what was wrong and how to fix it save more support time than any other feature.
What does API infrastructure need?
A gateway or proxy for TLS, authentication checks and limits, application servers, a data store and monitoring of latency and error rates per endpoint. Open-source gateways such as Kong, Tyk or KrakenD run on your own machines, or NGINX and HAProxy do the essentials. ESSENTIAL-2 hosts a modest API at $43.20 a month; busy ones spread across several machines with a load balancer. Every server includes DDoS filtering against floods, while per-client limits handle abusive callers. Our Web server article covers the proxy layer.
Machines for API services
| Model | Processor | Cores | Memory | Drives | Port | Per month |
|---|---|---|---|---|---|---|
| ESSENTIAL-1 | Intel Xeon-E 2386G | 6 | 32 GB | 2x 512 GB SSD NVMe | 1 Gbps unmetered | $38.40 |
| ESSENTIAL-2 | Intel Xeon-E 2388G | 8 | 32 GB | 2x 512 GB SSD NVMe | 1 Gbps unmetered | $43.20 |
| ESSENTIAL-3 | AMD Ryzen 9 5900X | 12 | 32 GB | 2x 512 GB SSD NVMe | 1 Gbps unmetered | $61.20 |
| BUSINESS-1 2024 | AMD EPYC 4244P | 6 | 32 GB | 2x 960 GB SSD NVMe | 3 Gbps unmetered | $81.60 |
Related pages
REST API
The resource-oriented style behind most web APIs: resources and URLs, HTTP methods and status codes, statelessness, pagination, versioning and hosting.
Read moreWeb application
Software used through a browser: how front end, back end and data layers fit together, common architectures and hosting one on your own server.
Read moreWeb server
Both the software that answers HTTP requests and the machine running it: request handling, popular servers, virtual hosts, HTTP versions and sizing.
Read moreMicroservices architecture
Splitting an application into small independent services: benefits, the costs people underestimate, communication patterns, data ownership and running them on bare metal.
Read moreQuestions and answers
What does API stand for?
Application programming interface: a defined way for software components to request services and data from each other.
Is every API a web API?
No. Libraries, operating systems and hardware all have APIs. In everyday use the term often means a web service reached over HTTP.
Which is better, REST or GraphQL?
Neither in general. REST is simpler and caches well; GraphQL lets clients request exactly the fields they need. Many systems use both.
How should an API key be stored?
In a secrets manager or protected configuration on the server, never in browser code, mobile apps or public repositories.
What is a webhook?
An HTTP request a service sends to your URL when an event happens, so you receive updates without polling. Verify its signature before trusting it.