API Exploration Template – AniVation Tech Academy

📦 Topic: How APIs Work + Python Demo

🎯 Skill Focus: Understanding API requests, responses, and basic Python usage

🛠 Tools: Notion, Python (SkillStruck / Replit / VSCode), requests library


1️⃣ What Is an API?

API stands for Application Programming Interface. It’s a way for two different pieces of software to talk to each other and share data or services.

Think of it like:


2️⃣ How Does It Work? (Step-by-Step Logic)

Step What Happens Example
1. Client sends a request You ask the server for something “What’s the weather in San Bernardino?”
2. Request goes to a URL A special web address called an endpoint https://api.weather.com/forecast?city=sanbernardino
3. Server checks your request Valid format? Auth key? Are you allowed to ask this question?
4. Server processes it Looks up the data or runs a function Finds weather data from a database
5. Server sends back a response Usually in JSON format A big chunk of text with temperature, time, etc.

📝 APIs usually need an API key — like a password that proves you’re allowed to use it.


3️⃣ Python Example: Calling a Weather API

Paste this code into Replit or your Python editor:

import requests

# Step 1 – Choose the API URL and parameters
url = "<https://api.open-meteo.com/v1/forecast>"
params = {
    "latitude": 34.1,      # San Bernardino
    "longitude": -117.3,
    "hourly": "temperature_2m"
}

# Step 2 – Send the request
response = requests.get(url, params=params)

# Step 3 – Check for success
if response.status_code == 200:
    data = response.json()
    print("First 5 temperatures:")
    print(data["hourly"]["temperature_2m"][:5])
else:
    print("Error:", response.status_code)