Course එකට ආපසු

APIs Simplified

15 මිනිත්තු📖Lecture

🎯 පාඩමේ අරමුණු

මේ පාඩම ඉවර වෙද්දී ඔයාට:

  • API එකක් plain English වලින් තේරුම් ගන්න පුළුවන් වෙයි
  • Every day APIs use කරන විදිය recognize කරන්න පුළුවන් වෙයි
  • AI tools APIs use කරන විදිය දැකගන්න පුළුවන් වෙයි
  • Basic API vocabulary දැනගන්න පුළුවන් වෙයි

📖 API එක කුමක්ද?

API යනු Application Programming Interface.

Technical වගේ sound වෙනවා, but simple explanation එක මෙන්න:

Plain English වලින් API

API එකක් යනු service එකකින් ඔයාට කරන්න පුළුවන් actions menu එකක්.

Restaurant menu එකක් dishes order කරන්න පුළුවන් මොනවද list කරනවා වගේ, API එකක් software service එකකින් request කරන්න පුළුවන් operations මොනවද list කරනවා.


🍽️ Restaurant Menu Analogy එක (Expanded)

Menu නැතුව (API නැහැ):

  • ඔයාම kitchen එකට යන්න ඕන
  • Every dish cook කරන විදිය ඉගෙන ගන්න ඕන
  • Ingredients හැමඑකම store කරලා තියෙන්නේ කොහෙද දැනගන්න ඕන
  • Kitchen equipment තේරුම් ගන්න ඕන

Customer කෙනෙකුට ඒක impossible! Food විතරක් ඕන.

Menu එක්ක (API):

  • Available options බලනවා
  • ඕන දේ choose කරනවා
  • Waiter ට order එක කියනවා
  • Kitchen prepare කරනවා
  • Exactly ask කළ දේ receive කරනවා

API එක menu එක. ඔයාට CAN ask කරන්න මොනවද HOW ask කරන්නද කියලා කියනවා.


🌍 Real-World API Examples

Realize නොකර constantly APIs use කරනවා:

Weather Apps

ඔයා දකින දේ
Actually වෙන දේ
72°F, Sunny in Colombo
ඔයාගේ app weather API එකට ask කළා: 'Colombo වල weather මොකක්ද?'

Weather API menu එකේ includes:

  • Current temperature ගන්න
  • Next 7 days forecast ගන්න
  • Humidity සහ wind speed ගන්න
  • Sunrise/sunset times ගන්න

Maps & Navigation

ඔයා දකින දේ
Actually වෙන දේ
A ඉඳන් B ට route එක travel time එක්ක
ඔයාගේ app Maps API එකට ask කළා: 'A ඉඳන් B ට යන්නේ කොහොමද?'

Maps API menu එකේ includes:

  • Points අතර directions ගන්න
  • Travel time calculate කරන්න
  • Nearby restaurants find කරන්න
  • Traffic conditions show කරන්න

Social Media

ඔයා දකින දේ
Actually වෙන දේ
Friends ගේ latest posts
App Social API එකට ask කළා: 'මේ user ට recent posts ගන්න'

Payment Processing

ඔයා දකින දේ
Actually වෙන දේ
'Payment successful'
Website Payment API එකට ask කළා: 'මේ card එකට $50 charge කරන්න'

🤖 AI APIs Use කරන විදිය

Phone එකෙන් ChatGPT හෝ Claude එක්ක chat කරනකොට, මෙන්න happen වෙන දේ:

Text
┌──────────────────────────────────────────────────────────┐
│ │
│ 📱 ඔයාගේ Phone │
│ │ │
│ │ ඔයා type කරනවා: "Photosynthesis simply explain කරන්න"│
│ │ │
│ ▼ │
│ 🌐 Internet │
│ │ │
│ │ ඔයාගේ message OpenAI API එකට send වෙනවා │
│ │ │
│ ▼ │
│ 🖥️ OpenAI Servers │
│ │ │
│ │ AI ඔයාගේ message process කරනවා │
│ │ Response generate කරනවා │
│ │ │
│ ▼ │
│ 🌐 Internet │
│ │ │
│ │ Response ආපහු send වෙනවා │
│ │ │
│ ▼ │
│ 📱 ඔයාගේ Phone │
│ │ │
│ │ ඔයා දකිනවා: "Photosynthesis cooking වගේ..." │
│ │
└──────────────────────────────────────────────────────────┘

Key Insight

AI ඔයාගේ phone එකේ run වෙන්නේ නැහැ. ඔයාගේ phone just API එකට answers ask කරනවා.


📋 API Vocabulary

TermPlain EnglishExample
RequestAPI එකට ඔයා send කරන දේ (ඔයාගේ order)"London weather මොකක්ද?"
Responseඔයාට receive වෙන දේ (ඔයාගේ food)"London: 15°C, Partly Cloudy"
EndpointSpecific action එකක specific URL එකක්/api/weather, /api/forecast
API Keyඔයාව identify කරන passwordAPI-KEY: sk-abc123xyz789
Rate LimitRequests කීයක් කරන්න පුළුවන්ද"Free: 100/day, Pro: 10,000/day"

🔄 Request-Response Cycle එක

Every API interaction මේ pattern follow කරනවා:

Text
1. CLIENT (ඔයා/ඔයාගේ app)
│ REQUEST කරනවා
│ "Tokyo weather ගන්න"
2. API ENDPOINT
│ Request process කරනවා
│ Data fetch කරනවා
│ Response prepare කරනවා
3. CLIENT RESPONSE receive කරනවා
│ "Tokyo: 25°C, Sunny,
│ Humidity: 60%"
4. APP user ට data display කරනවා

💡 Vibe Coding වලට APIs Matter වෙන්නේ ඇයි

1. Possible මොනවද දැනගන්න

APIs define කරනවා service එකකින් කරන්න පුළුවන් සහ බැරි මොනවද. API endpoint එකක් නැත්නම්, programmatically ඒක කරන්න බැහැ.

2. Better Prompt කරන්න

Weather API එකක් තියෙනවා කියලා දන්නකොට, AI ට ask කරන්න පුළුවන්:

API-Aware Prompt
OpenWeatherMap API use කරලා weather show කරන webpage create කරන්න. Current temperature, conditions, 5-day forecast include කරන්න.
ChatGPTClaude

3. Errors තේරුම් ගන්න

මොකක් හරි work නොකරන විට, often API issue එකක්:

  • "API key invalid" → Wrong password
  • "Rate limit exceeded" → Requests ගොඩක්
  • "Endpoint not found" → Wrong address

4. Connected Apps Build කරන්න

Modern apps multiple APIs combine කරනවා:

  • Weather API + Maps API = "Route එකේ weather"
  • Payment API + Email API = "Purchase එකට පස්සේ receipt sent"
  • AI API + Speech API = "Voice assistant"

📊 Encounter වෙන Common APIs

CategoryExample APIsකරන දේ
AI/MLOpenAI, Anthropic, Google AIText generation, image analysis
WeatherOpenWeatherMap, WeatherAPIWeather data සහ forecasts
MapsGoogle Maps, MapboxDirections, locations, maps
PaymentsStripe, PayPalTransactions process කිරීම
EmailSendGrid, MailgunProgrammatically emails send කිරීම
SocialTwitter, FacebookContent post කිරීම, feeds read කිරීම
StorageAWS S3, CloudinaryFiles සහ images store කිරීම
AuthAuth0, Firebase AuthUser login systems

🎮 Action එකේ API

API Understanding නැතුව:

"Weather app එකක් හදන්න"

(AI guess කරන්න ඕන ඔයා mean කරන්නේ මොකක්ද)

API Understanding එක්ක:

Informed Prompt
Simple weather card එකක් create කරන්න: 1. City name input ලෙස ගන්නවා 2. Current weather ගන්න OpenWeatherMap API call කරනවා 3. Temperature, conditions, icon display කරනවා 4. City find නොවුනොත් errors handle කරනවා
ChatGPTClaude

Behind scenes වෙන දේ තේරුම් ගත්තම second prompt AI ට clear direction දෙනවා.


✅ පාඩමේ සාරාංශය

එක Sentence එකෙන් API

API එකක් service එකකින් perform කරන්න ask කරන්න පුළුවන් actions menu එකක්.

Key Concepts:

TermPlain English
APIAvailable actions menu එකක්
RequestAsk කරන දේ
ResponseBack ලැබෙන දේ
EndpointSpecific action එකේ address
API KeyService use කරන්න ඔයාගේ password
Rate LimitRequests කරන්න පුළුවන් කීවතාවක්

📝 Mini Quiz

📝 ඔයාගේ Understanding Check කරන්න

1/3

What is an API in plain English?