Chapter 1: What Is an API?
API stands for Application Programming Interface. It is how different software systems communicate with each other.
Why APIs Matter
APIs are the foundation of modern software development:
- Reusability: Instead of building everything from scratch, you use existing APIs
- Specialization: Companies focus on what they do best and expose it via APIs
- Composition: Combine multiple APIs to create powerful applications
- Ecosystem: APIs create platforms that others build upon
What Is an API?
An API defines a contract between two software systems:
Client (frontend app, mobile app, another server)
-> sends REQUEST to API
-> API validates, processes, fetches data
-> returns RESPONSE to client
The request specifies what data or action is needed. The response contains the result.
The Restaurant Analogy
- You (client): Hungry, want beef noodles
- Waiter (API): Takes your order to the kitchen
- Kitchen (server): Cooks the food
- Waiter (API): Brings your food back
You do not need to know how the kitchen works. You just need to communicate through the waiter (API).
How APIs Work
APIs typically use HTTP as the communication protocol:
GET /api/users HTTP/1.1
Host: example.com
Authorization: Bearer token123
The server responds with data, usually in JSON format:
{
"users": [
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
]
}
API Request Components
| Component | Description | Example | |-----------|-------------|---------| | HTTP Method | The action to perform | GET, POST, PUT, DELETE | | URL | The resource to access | /api/users/123 | | Headers | Metadata about the request | Authorization, Content-Type | | Body | Data sent with the request (POST/PUT) | {"name": "Charlie"} |
API Response Components
| Component | Description | Example | |-----------|-------------|---------| | Status Code | Result of the request | 200 (OK), 404 (Not Found) | | Headers | Metadata about the response | Content-Type: application/json | | Body | The actual data returned | JSON object or array |
Common HTTP Methods
| Method | Purpose | Idempotent? | Safe? | |--------|---------|:-----------:|:----:| | GET | Retrieve data | Yes | Yes | | POST | Create new data | No | No | | PUT | Update/replace data | Yes | No | | PATCH | Partial update | Yes | No | | DELETE | Remove data | Yes | No |
Why APIs Changed Software Development
Before APIs, integrating different systems required direct database access or custom file exchanges. This was slow, fragile, and insecure.
| Era | Integration Method | Problems | |:----|:------------------|----------| | Pre-2000 | Direct DB access, FTP file transfer | Security risks, tight coupling | | 2000-2010 | SOAP web services | Heavy XML, complex standards | | 2010-present | RESTful APIs with JSON | Simple, lightweight, widely adopted | | 2020+ | GraphQL, gRPC | More efficient, strongly typed |
Real-World API Examples
Google Maps API
Want to display a map on your website? Instead of building a mapping system from scratch, you call Google Maps API:
const map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 25.0, lng: 121.5 },
zoom: 8,
});
Stripe Payment API
Want to accept credit card payments? Use Stripe API:
stripe.Charge.create(
amount=2000,
currency="usd",
source="tok_visa",
description="Course purchase",
)
OpenAI API
Want to add AI to your application? Use OpenAI API:
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}],
)
JSON Rules
JSON is the most common data format for APIs. Strict rules:
- Double quotes only: Keys and string values must use double quotes (")
- No trailing commas: The last item in an object or array must not have a comma
- No comments: JSON does not support comments
- Valid types: string, number, boolean, null, object, array
{
"name": "Vibe Tutor",
"courses": 489,
"active": true,
"metadata": null,
"tags": ["coding", "AI"]
}
The Vibe Coding Approach
Describe what you need:
"I need to fetch user data from an API. The API endpoint is GET /api/users. It returns JSON with id, name, and email fields. Write a React component that fetches this data and displays it in a table."
The AI will generate the complete fetch logic with loading states and error handling.
Summary
APIs are the building blocks of modern software. They enable different systems to communicate, allow developers to reuse existing capabilities, and create ecosystems of composable services.
Key takeaways:
- API = defined contract between software systems
- HTTP methods: GET (read), POST (create), PUT (update), DELETE (remove)
- Request: method + URL + headers + body (optional)
- Response: status code + headers + body (usually JSON)
- JSON is the standard data format for modern APIs
- APIs power everything from Google Maps to AI assistants
- Vibe Coding: describe what you need, let AI handle the HTTP details
What's Next: Postman & Fetch
The next chapter teaches you to test APIs with Postman and call them from JavaScript code using the Fetch API.
The Business of APIs
APIs are not just technical - they are a business model:
API-as-a-Product
Companies like Twilio, Stripe, and OpenAI sell API access as their primary product:
| Company | What They Sell | API Pricing | |---------|---------------|-------------| | Twilio | SMS, voice, email APIs | Pay per message/minute | | Stripe | Payment processing API | 2.9% + $0.30 per transaction | | OpenAI | AI model APIs | Pay per token | | Google Maps | Maps, directions, places | Pay per 1000 requests | | AWS | Cloud infrastructure APIs | Pay per resource/hour |
The Integration Business
Many high-value freelance projects involve connecting two systems via their APIs:
- Connect an ERP system to LINE messaging
- Sync Shopify orders to QuickBooks accounting
- Automate invoice generation from Stripe payments
These integration projects typically range from $5,000 to $50,000+ depending on complexity.
API-First Design
Modern software development follows "API-first" design:
- Design the API contract first (what endpoints, what data)
- Document the API with OpenAPI/Swagger
- Build the frontend against a mock API
- Build the backend to match the contract
- Test everything together
This approach enables frontend and backend teams to work in parallel.
Summary
APIs are the foundation of modern software. They enable communication between systems, allow developers to reuse existing capabilities, and create new business models.
Key takeaways:
- API = Application Programming Interface, a contract between systems
- HTTP methods: GET (read), POST (create), PUT (update), DELETE (remove)
- Request includes: method, URL, headers, optional body
- Response includes: status code, headers, body (usually JSON)
- JSON rules: double quotes, no trailing commas, no comments
- APIs power Google Maps, Stripe, OpenAI, and thousands of other services
- API integration projects are high-value freelance opportunities
- API-first design enables parallel frontend/backend development
What's Next: Postman & Fetch
The next chapter teaches you to test APIs with Postman and call them from code using the Fetch API.