By the end of this lesson, you will:
ℹ️ Info What is an API? API stands for Application Programming Interface. It's a way for different computer programs to talk to each other and share information. Think of it like a menu at a restaurant - it tells you what you can order and how to ask for it!
Imagine you're at a restaurant:
Restaurant | API World | What Happens |
---|---|---|
You | Your Web App | Want something (like food or data) |
Menu | API Documentation | Shows what's available |
Waiter | API | Takes your order to the kitchen |
Kitchen | Server | Prepares what you asked for |
Your Food | API Response | What you get back |
When you check the weather on your phone:
You're already using APIs without knowing it!
What You Do | API Working Behind the Scenes |
---|---|
Check Instagram | Instagram API loads photos and comments |
Play Spotify | Spotify API streams music to your device |
Use Google Maps | Maps API shows directions and locations |
Watch YouTube | YouTube API loads videos and recommendations |
💡 Fun Fact When you "Sign in with Google" on a website, that website is using Google's API to check who you are!
The easiest way to see an API in action is using your browser! Your browser can make GET requests just by visiting a URL.
Try this:
https://api.github.com/users/octocat
You should see something like this:
{
"login": "octocat",
"name": "The Octocat",
"company": "@github",
"location": "San Francisco",
"bio": "GitHub's mascot"
}
Congratulations! You just made your first API call! 🎉
What you're seeing is called JSON (JavaScript Object Notation). It's how APIs send data:
{
"name": "Alex", // Text (called a string)
"age": 14, // Number
"isStudent": true, // Boolean (true/false)
"favoriteColors": ["blue", "green"] // List (called an array)
}
JSON looks like this:
{}
for objects (groups of information)[]
for arrays (lists of things)GET is the simplest API method. It just reads information without changing anything.
Think of GET like:
GET requests are safe because they:
Copy these URLs into your browser to see real API responses:
API URL | What You'll See |
---|---|
https://catfact.ninja/fact |
A random cat fact |
https://official-joke-api.appspot.com/random_joke |
A random joke |
https://api.nationalize.io/?name=michael |
Name origin predictions |
When you try these APIs, notice:
Regular Website | API |
---|---|
Returns HTML pages for humans to read | Returns data for programs to use |
Has colors, fonts, images | Just raw data (usually JSON) |
Meant to look pretty | Meant to be efficient |
You click buttons and links | Programs make requests |
Try changing the username in this URL:
https://api.github.com/users/[username]
Replace [username]
with:
torvalds
(Linux creator)gvanrossum
(Python creator)This API gives fun facts about numbers:
http://numbersapi.com/42/trivia?json
Try changing 42
to:
Each API returns different data, but it's always structured. Look for:
"like this"
42
["item1", "item2"]
{"key": "value"}
Today you learned:
Great job! You've taken your first step into the world of APIs. In the next lesson, we'll learn how to use JavaScript to make API calls and display the data on a webpage!
In Concept 02, you'll learn to: