[Class Report] Systems Development (Year 3) — Week 43
~Your First API Implementation: Experiencing Requests and Responses~
In Week 43, building on last week’s foundational API knowledge, we ran a hands-on exercise where students actually called an external API.
This week marked the shift from “reading” to “using,” and students got their first real feel for communicating with an external service.
■ Teacher’s Introduction: “Today is the day you write code that talks to the outside world.”
Mr. Tanaka: “Today, for the first time, your code will communicate with something outside the school.
What matters is not only success, but also seeing what happens when things fail.”
The teacher reaffirmed these assumptions for today’s practice:
- We will use a learning-only API key.
- Even if you call an API exactly as documented, it won’t always succeed.
■ Today’s Goals
- Learn to send HTTP requests in code
- Receive API responses (JSON) and extract the necessary information
- Observe error responses and implement exception handling
- Get a feel for integrating API calls into the Service layer
■ Exercise ①: Re-check the API Documentation
First, students reviewed the API each of them researched as homework:
- Endpoint (URL)
- HTTP method (GET / POST)
- Required parameters
- Example response
- Error codes (400 / 401 / 404 / 500, etc.)
Student A: “I realized that if you don’t properly read the docs, you won’t understand why it doesn’t work.”
The teacher emphasized: “Half of API implementation is reading documentation.”
■ Exercise ②: Write a Simple API Call
Using Python, students wrote a minimal API call.
Learning Sample (Conceptual Understanding)
import requests
url = "https://api.example.com/weather"
params = {"city": "Tokyo"}
response = requests.get(url, params=params, timeout=5)
response.raise_for_status() # turn HTTP errors into exceptions
data = response.json()
print(data)
Key points checked here:
- Whether the URL and parameters were being sent correctly
- Status codes (200 / 400 / 401, etc.)
- That JSON can be handled as a dictionary
Student B: “When I printed it, there was way more data than I expected!”
■ Exercise ③: Extract Only the Needed Data
Next, students practiced using only the necessary fields from the full response.
temp = data["current"]["temp"]
condition = data["current"]["condition"]
print(f"Current temperature: {temp}°C / Weather: {condition}")
Teacher’s advice:
- Only display what you need right now
- Assume the API response structure might change someday
Student C: “It feels like being able to read JSON connects to design skills.”
■ Exercise ④: Intentionally Trigger Errors
APIs don’t succeed all the time.
So students intentionally tested cases like:
- Using incorrect parameters
- Removing the API key
- Specifying a URL that doesn’t exist
try:
response = requests.get(url, params=params, timeout=5)
response.raise_for_status()
except requests.exceptions.HTTPError as e:
print("An HTTP error occurred")
except requests.exceptions.Timeout:
print("Request timed out")
except Exception as e:
print("Unexpected error:", e)
Student D: “It’s important that the program doesn’t just crash when an error happens.”
■ Exercise ⑤: Move the API Call into the Service Layer
Finally, applying the design principles learned in Year 2, students separated the API call into a Service layer (ExternalService).
UI
↓
WeatherService
↓
WeatherApiClient
↓
External API
Key points:
- Don’t call the API directly from the UI
- Make failure-handling decisions in the Service
- Design so you can swap the API later if needed
Student E: “I didn’t expect Year 2’s design lessons to matter this much here!”
■ Classwide Takeaways
- APIs are “useful,” but also “unstable.”
- Without error handling, programs fail easily.
- You don’t need to use every field in the response.
- Implementing after designing reduces confusion.
■ Teacher’s Closing Note
“Today, your code had its first conversation with the outside world.
Using an API means handling something you can’t fully control.
That’s why what you learned in Year 2—separation of responsibilities, exception handling, and logging—starts to matter in a very real way.”
■ Homework (For Next Week)
- Organize today’s API call into a Service class and submit it
- Write a short explanation of behavior on success vs. failure
- Propose one fallback plan for when the API cannot be used
■ Next Week Preview: Integrating the API into an App
Next week, students will integrate the retrieved API data into their own application use cases.
This is the step from “It works” to “It’s useful.”
Week 43 was a memorable milestone:
students’ systems connected to the world outside the school for the first time.
Even with some confusion, they experienced both the potential and the difficulty of API integration—
and their Year 3 learning is now truly picking up momentum.
