API (Application Programming Interface)
About 5 min read
Last updated: 2026-04-28
What Is an API
An API (Application Programming Interface) is a set of rules that allows software applications to communicate and exchange data. Think of a restaurant: the customer (application) reads the menu (API specification), places an order, and the waiter (API) relays it to the kitchen (server) and brings back the dish (data).
Your weather app displays current conditions by fetching data through a weather service API. Modern web services combine dozens to hundreds of APIs behind the scenes.
Main Types of APIs
API Authentication and Authorization
Secure API usage requires both authentication (who is accessing) and authorization (what they can do).
- API Keys: The simplest method. A fixed string included in request headers. Easy but risky if leaked.
- OAuth 2.0: Enables third-party authentication like "Sign in with Google" without sharing passwords directly.
- JWT (JSON Web Token): Embeds authentication data in a token that can be verified without server-side sessions. Works well with stateless API designs.
Hardcoding API keys in source code or committing them to public repositories remains a common mistake. Use secret management tools and environment variables.
Rate Limiting and API Protection
Rate limiting caps the number of API requests accepted within a time window. Without it, attackers can overwhelm servers with DDoS attacks.
- Fixed Window: Limits requests per fixed time period (e.g., 100 per minute). Simple but allows bursts at window boundaries.
- Sliding Window: Continuously tracks requests over the last time period, eliminating boundary bursts.
- Token Bucket: Tokens replenish at a steady rate and are consumed per request. Allows short bursts while controlling long-term averages.
When rate limited, servers return HTTP 429 (Too Many Requests). API consumers should implement exponential backoff retry logic.
API Security in Practice
APIs are the backbone of modern web services and a primary target for attackers. The OWASP API Security Top 10 highlights broken authentication, object-level authorization flaws, and excessive data exposure.
- Input Validation: Validate all request parameters to prevent SQL injection and XSS.
- HTTPS Enforcement: Always encrypt API traffic with TLS. Sending API keys over plain HTTP exposes them to interception.
- Least Privilege: Grant API tokens only the minimum required permissions.
- Logging and Monitoring: Monitor API call patterns to detect anomalous access early.
Common Misconceptions
- APIs are only relevant to developers
- APIs power smartphone apps, IoT devices, payment systems, and more. Logging into social media, paying with digital wallets, and using ride-sharing apps all rely on APIs.
- Private APIs are automatically secure
- Internal APIs can be exploited if the network is compromised or through supply chain attacks. Zero-trust principles - authentication, authorization, and encryption for internal APIs - are essential.
- REST is outdated and being replaced by GraphQL
- GraphQL excels in specific use cases, but REST is not inferior in all scenarios. For simple CRUD operations and caching, REST is often more appropriate. Both coexist.