Intro To APIs
Connect clients, servers, and data using contract-driven interfaces.
Curriculum
System Design Foundations
Scalability Basics
Database Design
Intro To APIs — Beginner Friendly System Design Guide
APIs Power Almost Everything
When you:
- order food on Swiggy
- pay using PhonePe
- book tickets on IRCTC
- scroll Instagram
- watch YouTube
APIs are working behind the scenes.
Modern apps communicate using APIs.
What Is An API?
API stands for:
Application Programming Interface
Very simple meaning:
API is a messenger between systems.
It allows:
- apps
- servers
- databases
- services
to communicate with each other.
Simple Real-Life Analogy
Restaurant Example
Imagine you visit restaurant.
You
You place order.
Waiter
Waiter takes your request to kitchen.
Kitchen
Kitchen prepares food.
Waiter Returns Food
You receive response.
API Mapping
| Real World | Software World |
|---|---|
| Customer | Client |
| Waiter | API |
| Kitchen | Server |
| Food | Response |
Real Example — Swiggy
Suppose you open Swiggy app.
You search:
Burger in Jaipur
Swiggy app itself does NOT know restaurants.
It asks backend server using API.
Swiggy API Flow
User Searches Burger
│
▼
Swiggy Mobile App
│
▼
API Request Sent
│
▼
Application Server
│
┌──────┼──────┐
▼ ▼
Cache Database
│
▼
Restaurant Data Returned
│
▼
App Displays Restaurants
API Request Example
Client sends request:
GET /restaurants?city=jaipur
API Response Example
Server returns:
[
{
"name": "Burger King",
"rating": 4.2
},
{
"name": "McDonalds",
"rating": 4.1
}
]
Why APIs Exist
Without APIs:
- frontend cannot talk to backend
- apps cannot communicate
- systems remain disconnected
APIs standardize communication.
APIs Connect Everything
Modern systems are made of:
- clients
- backend services
- databases
- external systems
APIs connect all of them.
Complete API Architecture
Mobile App / Browser
│
▼
API
│
▼
Application Server
│
┌────────┼─────────┐
▼ ▼
Database External APIs
Types Of API Requests
GET — Fetch Data
Used for reading data.
Example
GET /products
Fetches products.
POST — Create Data
Used for creating data.
Example
POST /orders
Creates order.
PUT — Update Data
Used for updating existing data.
Example
PUT /user/1
Updates user.
DELETE — Remove Data
Used for deleting data.
Example
DELETE /cart/5
Deletes cart item.
API Request-Response Model
Most APIs follow:
Request → Processing → Response
Generic API Flow
Client App
│
▼
API Request
│
▼
Server Processes Logic
│
┌──┴─────────┐
▼ ▼
Database Cache
│
▼
API Response
│
▼
Client Updates UI
Real Example — PhonePe Payment
When you pay ₹500:
Payment Flow
PhonePe App
│
▼
Payment API Request
│
▼
Bank Server
│
▼
NPCI Network
│
▼
Receiver Bank
│
▼
Payment Success Response
APIs Are Contracts
APIs define:
- what request looks like
- what response looks like
- what data allowed
Both frontend and backend follow same contract.
Example API Contract
Request
GET /user/1
Response
{
"id": 1,
"name": "Rahul"
}
Frontend expects this structure.
Why API Contracts Matter
Without contracts:
- frontend breaks
- mobile apps crash
- integrations fail
Contracts create predictability.
APIs In Microservices
Modern systems use:
- many small services
They communicate using APIs.
Example — Ecommerce Architecture
Frontend App
│
▼
API Gateway
│
┌───┼────────────┐
▼ ▼ ▼
User Product Payment
API API API
Each service exposes APIs.
REST APIs
Most common API style.
Uses:
- HTTP
- JSON
- URLs
Example REST API
GET /products/101
GraphQL APIs
Client asks only required data.
Example
Instead of full response:
client asks:
Only product name and price
Useful for:
- mobile apps
- optimized data fetching
Internal APIs vs External APIs
| Type | Example |
|---|---|
| Internal API | Swiggy services talking internally |
| External API | Razorpay payment API |
Example External API Usage
Swiggy may use:
- Google Maps API
- Razorpay API
- SMS APIs
instead of building everything themselves.
Authentication In APIs
Not everyone should access APIs.
Systems use:
- tokens
- API keys
- JWT
- OAuth
Secure API Flow
Client Sends Token
│
▼
API Verifies Token
│
┌────┴────┐
▼ ▼
Valid Invalid
│ │
▼ ▼
Process Reject
Request
API Latency
Every API call takes time.
Latency sources:
- internet
- backend processing
- database queries
- external services
Example
| API Type | Approximate Latency |
|---|---|
| Local cache | 1-5 ms |
| Database query | 5-50 ms |
| External API | 100-500 ms |
APIs At Scale
Large companies handle:
- millions of API requests per second
Example:
- Instagram feed APIs
- YouTube streaming APIs
- UPI payment APIs
Scaled API Architecture
Users
│
▼
Load Balancer
│
┌─┼─────────┐
▼ ▼ ▼
API1 API2 API3
│
▼
Database Cluster
Common API Problems
| Problem | Example |
|---|---|
| Slow API | Database bottleneck |
| Timeout | External service delay |
| Rate limiting | Too many requests |
| Invalid response | Contract mismatch |
| Unauthorized access | Missing token |
Common Beginner Misconceptions
"API Means Backend"
No.
API is communication layer between systems.
"Frontend Directly Uses Database"
Usually no.
Safe architecture:
Frontend
│
▼
API
│
▼
Backend
│
▼
Database
"APIs Are Only For Mobile Apps"
No.
APIs are used everywhere:
- frontend
- backend
- microservices
- third-party integrations
APIs And System Design
APIs influence:
- scalability
- latency
- reliability
- architecture
- developer experience
Well-designed APIs simplify systems.
Poor APIs create chaos.
Final Mental Model
Frontend = User Interface
API = Communication Layer
Backend = Business Logic
Database = Storage
Complete Real-World Architecture
Mobile App / Browser
│
▼
Internet
│
▼
API Gateway
│
┌────────┼────────┐
▼ ▼
User Service Payment Service
│
▼
Database
│
▼
Response Returned
One-Line Interview Definition
An API is a contract-driven communication layer that enables clients, servers, and services to exchange data and functionality over a network.
Module context
How the internet actually works, the client-server model, databases, and APIs. The building blocks every architect needs before anything else.