HTTP & APIs

API

An API is a defined contract that lets one software component request data or actions from another without knowing its internal implementation.

Diagram

  Mobile App ──▶ [API Contract] ──▶ Backend Server
                 (endpoints + rules)     (hidden internals)
  
  Client only sees: GET /users, POST /orders
  Client never sees: database schema, business logic

In Depth

API stands for Application Programming Interface. A web API exposes a set of endpoints and rules that external clients (mobile apps, other services, third-party developers) use to read or modify data.

Code Example

Calling a public API

const response = await fetch('https://api.stripe.com/v1/charges', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer sk_live_...' },
  body: JSON.stringify({ amount: 2000, currency: 'usd' }),
});
const charge = await response.json(); // 201 Created

⚠️ Common Misconception

An API is not the same as a database. The API is the controlled front door; the database is the private storage room behind it. Clients should never connect to the database directly.

🌍 Real World Usage

Stripe's payment API, GitHub's repo API, and Twitter's timeline API power thousands of third-party apps — all through HTTP endpoints.

Related Terms