Understanding Web APIs Through Everyday Analogies
API = Application Programming Interface
You (Client): Want to order food but can't go into the kitchen
Menu (API Documentation): Shows what you can order and how to order it
Waiter (API): Takes your order to the kitchen and brings back your food
Kitchen (Server): Prepares the food but you never interact with it directly
In Software Terms:
Why APIs Matter: Instagram doesn't store all photos on your phone. When you open the app, it uses APIs to fetch your feed, post photos, load comments, etc.
REST is a set of guidelines for building APIs that are predictable, scalable, and easy to use.
Resources: Books are identified by call numbers (URLs)
Actions: Checkout, return, reserve (HTTP methods)
Stateless: Each request is independent - librarian doesn't remember you
Standard Format: All requests follow the same rules
| Principle | What It Means | Example |
|---|---|---|
| Resources | Everything is a "thing" with a URL | /users/123, /posts/456, /models/789 |
| HTTP Methods | Actions you can do to resources | GET (read), POST (create), PUT (update), DELETE (remove) |
| Stateless | Each request is independent | Every request includes all needed information (like showing ID each time) |
| Standard Format | Data sent/received in predictable format | JSON is the most common format |
GET: Check your balance (view only, doesn't change anything)
POST: Deposit money (create something new)
PUT: Update your PIN (modify existing thing)
DELETE: Close account (remove something)
Purpose: Retrieve data
Safe: Yes (doesn't change anything)
Example: View a profile
Purpose: Create new resource
Safe: No (creates something)
Example: Submit a new post
Purpose: Update existing resource
Safe: No (modifies something)
Example: Edit your bio
Purpose: Remove resource
Safe: No (deletes something)
Example: Delete a photo
2xx (Success): "Your package was delivered!" ✅
4xx (Client Error): "Wrong address - can't deliver" 🏠❌
5xx (Server Error): "Post office is closed - try later" 🏢❌
Request successful, here's your data
Successfully created new resource
Success, but no data to return
Your request is malformed or invalid
You need to log in first
That resource doesn't exist
Data format is wrong
Something broke on the server
| Company | What Their API Does | Example Endpoint |
|---|---|---|
| Post tweets, read timeline, search | POST /tweets | |
| Spotify | Get recommendations, control playback | GET /recommendations |
| Google Maps | Get directions, geocode addresses | GET /directions |
| Netflix | Stream content, track watching | GET /continue-watching |
| Uber | Request rides, track drivers | POST /rides |