[Class Report] Introduction to System Development, Week 22 — Introduction to External API Integration: Learning HTTP and JSON
This week, as announced last time, we tackled the “basics of integrating with external APIs (external services)”.
We learned how different services “talk” to each other using mechanisms like HTTP, endpoints, and JSON, and tried building a simple example in practice.
■ Teacher’s Introduction: “APIs Are Agreements Between Services (Protocols)”
Mr. Tanaka: “An API is a ‘rulebook for reading and writing.’ If you follow the right agreement (how to send requests), you can receive data from or borrow functionality from another service.”
On the board, the flow of sending a URL request from a browser → server returning JSON was drawn, helping students visualize “services having a conversation.”
■ Today’s Key Points: HTTP Basics, JSON, API Keys, Status Codes
We first reviewed basic terms in short form:
- HTTP (GET/POST): How to ask a server “Give me information (GET)” or “Send information (POST).”
- Endpoint: The URL (window) for accessing an API.
- JSON: A commonly used data format shaped as “keys and values.”
- Status Code: A number indicating the response result — 200 (success), 404 (not found), 401 (authentication error), etc.
- API Key / Authentication: Some services require a key (API key) to use them. Keep it safe.
Student A: “So status codes show the type of error!”
Student B: “An API key should be treated like a password.”
■ Practice: Simple API Call in Python (Example)
In practice, we sent a GET request to an external service and learned how to parse the returned JSON and display it.
Here’s a simple example from class (educational pseudo-code):
import requests # Assumes requests is available in the learning environment
import json
url = "https://api.example.com/weather"
params = {"q": "Tokyo", "appid": "YOUR_API_KEY"} # Replace YOUR_API_KEY with your own key
response = requests.get(url, params=params)
if response.status_code == 200:
data = response.json() # Convert JSON to a Python dictionary
temp = data["main"]["temp"]
description = data["weather"][0]["description"]
print(f"Current temperature: {temp}℃, Weather: {description}")
else:
print(f"An error occurred: {response.status_code}")
The teacher added: “When using a real API, read the documentation carefully and check the usage (parameters, authentication, rate limits).”
■ Hands-On Exercise: Practice “Reading” and “Using” a Familiar API
Students worked on the following tasks (conducted in an environment that allowed actual API calls in compliance with school network policy):
- Choose one API documentation and note the endpoint and required parameters.
- Use
requests.get()
to actually retrieve data (where possible). - Extract and display necessary information from the returned JSON (e.g., weather, exchange rates, random quotes).
- Implement error handling for failed retrievals (display messages based on status codes).
Student C: “Reading the documentation is hard, but once I understood it, it was fun!”
Student D: “It’s tricky to follow the JSON hierarchy, but it feels great to see the data.”
■ Mini Lecture on Security and Etiquette
At the end of class, we reviewed important points when using APIs:
- Never put your API key in a public repository (manage secrets in
.env
files, etc.) - Observe rate limits (number of calls allowed within a certain time).
- Respect the terms of use (e.g., whether commercial use or redistribution is allowed).
Mr. Tanaka emphasized: “They’re convenient, but if you break the rules, you can cause trouble or damage.”
■ Teacher’s Comment
“Once you can use external APIs, you can integrate weather, maps, translation, and more into your apps. But that also comes with the ‘responsibility of use.’ Start by practicing with small APIs and learn to use them while following the rules.”
■ Next Week’s Preview: Mini Project with API Integration
Next week, we’ll use what we learned to build a small API integration project (e.g., a mini-app that fetches and displays the weather).
We’ll go through design → implementation → error handling from start to finish.
In Week 22, the first-year students experienced the excitement of “connecting to the outside world.” They’ll deepen their understanding further in the next practical exercise.