API stands for Application Programming Interface. It's a set of rules and protocols that allows different software applications to communicate with each other.
Think of an API like a waiter in a restaurant:
- You (Client) - Look at the menu and decide what you want
- Waiter (API) - Takes your order to the kitchen
- Kitchen (Server) - Prepares your food
- Waiter (API) - Brings your food back to you
The waiter is the intermediary that communicates between you and the kitchen, just like an API communicates between applications!
- Uses HTTP methods
- Stateless communication
- JSON data format
- Most common type
- XML-based
- More complex
- Used in enterprise systems
- Query language
- Request exactly what you need
- Single endpoint
- Real-time communication
- Two-way connection
- Used for chat apps, live updates
- Frontend and backend can be developed independently
- Different teams can work in parallel
- One API can serve multiple applications
- Web, mobile, desktop can use the same API
- Hide internal implementation
- Control access to data
- Easier to scale systems
- Can update backend without changing frontend
The URL where the API can be accessed:
https://api-learning.nisalgunawardhana.com/api/users
The HTTP verb (GET, POST, PUT, DELETE)
Metadata about the request:
Content-Type: application/json
Authorization: Bearer token123
Data sent to the server:
{
"name": "John Doe",
"email": "john@example.com"
}Data received from the server:
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"createdAt": "2026-01-11T10:00:00Z"
}Indicates success or failure (200, 404, 500, etc.)
Imagine you're building a weather app:
// Request
GET https://api.weather.com/current?city=London
// Response
{
"temperature": 15,
"condition": "Cloudy",
"humidity": 70
}Your app doesn't need to know how the weather data is collected or stored. The API handles all that complexity!
REST (Representational State Transfer) APIs have specific characteristics:
- Client-Server Architecture - Separated concerns
- Stateless - Each request is independent
- Cacheable - Responses can be cached
- Uniform Interface - Consistent structure
- Layered System - Can have multiple layers
APIs commonly use JSON (JavaScript Object Notation) for data exchange:
{
"user": {
"id": 1,
"name": "Alice",
"age": 25,
"isActive": true,
"hobbies": ["reading", "coding", "gaming"]
}
}Why JSON?
- Human-readable
- Lightweight
- Supported by all programming languages
- Easy to parse
- Social Media - Posting, liking, commenting
- Payment Processing - Stripe, PayPal
- Maps - Google Maps API
- Authentication - OAuth, login systems
- Data Retrieval - News, weather, stocks
In this repository, we have a simple User Management API:
- Create users
- Read user data
- Update user information
- Delete users
All without a database - just a JSON file!
Now that you understand what an API is, let's learn about:
- HTTP Methods - How to interact with APIs
- Status Codes - Understanding responses
- REST Principles - Best practices