Course එකට ආපසු

APIs Simplified

15 මිනිත්තු📖Lecture

🎯 Lesson Objectives

By the end of this lesson, you will:

  • Understand what an API is in plain English
  • Recognize how you use APIs every day
  • See how AI tools use APIs
  • Know basic API vocabulary

📖 What is an API?

API stands for Application Programming Interface.

That sounds technical, but here's the simple explanation:

API in Plain English

An API is a menu of actions you can ask a service to do for you.

Just like a restaurant menu lists what dishes you can order, an API lists what operations you can request from a software service.


🍽️ The Restaurant Menu Analogy (Expanded)

Without a Menu (No API):

  • You'd have to go into the kitchen yourself
  • Learn how to cook every dish
  • Know where all ingredients are stored
  • Understand the kitchen equipment

That's impossible for a customer! You just want food.

With a Menu (API):

  • You look at available options
  • You choose what you want
  • You tell the waiter your order
  • Kitchen prepares it
  • You receive exactly what you asked for

An API is the menu. It tells you what you CAN ask for and HOW to ask for it.


🌍 Real-World API Examples

You use APIs constantly without realizing it:

Weather Apps

What You See
What Actually Happens
72°F, Sunny in New York
Your app asked a weather API: 'What's the weather in New York?'

The Weather API menu includes:

  • Get current temperature
  • Get forecast for next 7 days
  • Get humidity and wind speed
  • Get sunrise/sunset times

Maps & Navigation

What You See
What Actually Happens
Route from A to B with travel time
Your app asked a Maps API: 'How do I get from A to B?'

The Maps API menu includes:

  • Get directions between points
  • Calculate travel time
  • Find nearby restaurants
  • Show traffic conditions

Social Media

What You See
What Actually Happens
Latest posts from friends
App asked Social API: 'Get recent posts for this user'

Payment Processing

What You See
What Actually Happens
'Payment successful'
Website asked Payment API: 'Charge $50 to this card'

🤖 How AI Uses APIs

When you chat with ChatGPT or Claude on your phone, here's what happens:

Text
┌──────────────────────────────────────────────────────────┐
│ │
│ 📱 Your Phone │
│ │ │
│ │ You type: "Explain photosynthesis simply" │
│ │ │
│ ▼ │
│ 🌐 Internet │
│ │ │
│ │ Your message is sent to OpenAI's API │
│ │ │
│ ▼ │
│ 🖥️ OpenAI's Servers │
│ │ │
│ │ AI processes your message │
│ │ Generates response │
│ │ │
│ ▼ │
│ 🌐 Internet │
│ │ │
│ │ Response sent back │
│ │ │
│ ▼ │
│ 📱 Your Phone │
│ │ │
│ │ You see: "Photosynthesis is like cooking..." │
│ │
└──────────────────────────────────────────────────────────┘

Key Insight

The AI isn't running on your phone. Your phone is just asking the API for answers.


📋 API Vocabulary

TermPlain EnglishExample
RequestWhat you send to the API (your order)"What's the weather in London?"
ResponseWhat you receive back (your food)"London: 15°C, Partly Cloudy"
EndpointA specific URL for a specific action/api/weather, /api/forecast
API KeyA password that identifies youAPI-KEY: sk-abc123xyz789
Rate LimitHow many requests you can make"Free: 100/day, Pro: 10,000/day"

🔄 The Request-Response Cycle

Every API interaction follows this pattern:

Text
1. CLIENT (you/your app)
│ Makes REQUEST
│ "Get weather for Tokyo"
2. API ENDPOINT
│ Processes request
│ Fetches data
│ Prepares response
3. CLIENT receives RESPONSE
│ "Tokyo: 25°C, Sunny,
│ Humidity: 60%"
4. APP displays data to user

💡 Why APIs Matter for Vibe Coding

1. Know What's Possible

APIs define what you can and can't do with a service. If there's no API endpoint for something, you can't do it programmatically.

2. Prompt Better

When you know there's a Weather API, you can ask AI:

API-Aware Prompt
Create a webpage that shows weather using the OpenWeatherMap API. Include current temperature, conditions, and a 5-day forecast.
ChatGPTClaude

3. Understand Errors

When something doesn't work, it's often an API issue:

  • "API key invalid" → Wrong password
  • "Rate limit exceeded" → Too many requests
  • "Endpoint not found" → Wrong address

4. Build Connected Apps

Modern apps combine multiple APIs:

  • Weather API + Maps API = "Weather along your route"
  • Payment API + Email API = "Receipt sent after purchase"
  • AI API + Speech API = "Voice assistant"

📊 Common APIs You'll Encounter

CategoryExample APIsWhat They Do
AI/MLOpenAI, Anthropic, Google AIText generation, image analysis
WeatherOpenWeatherMap, WeatherAPIWeather data and forecasts
MapsGoogle Maps, MapboxDirections, locations, maps
PaymentsStripe, PayPalProcess transactions
EmailSendGrid, MailgunSend emails programmatically
SocialTwitter, FacebookPost content, read feeds
StorageAWS S3, CloudinaryStore files and images
AuthAuth0, Firebase AuthUser login systems

🎮 API in Action

Without API Understanding:

"Make a weather app"

(AI has to guess what you mean)

With API Understanding:

Informed Prompt
Create a simple weather card that: 1. Takes a city name as input 2. Calls the OpenWeatherMap API to get current weather 3. Displays temperature, conditions, and an icon 4. Handles errors if city isn't found
ChatGPTClaude

The second prompt gives AI clear direction because you understand what's happening behind the scenes.


✅ Lesson Summary

API in One Sentence

An API is a menu of actions you can ask a service to perform.

Key Concepts:

TermPlain English
APIA menu of available actions
RequestWhat you ask for
ResponseWhat you get back
EndpointThe specific action's address
API KeyYour password to use the service
Rate LimitHow often you can make requests

📝 Mini Quiz

📝 Check Your Understanding

1/3

What is an API in plain English?