Intermediate level · Module 4 of 6 · 18 guided hours
Working with Web APIs
Retrieve live data from web services, process the JSON responses and cope with unreliable connections.
Learning objectives
- Explain HTTP requests, responses and status codes
- Call REST APIs with the requests library
- Handle timeouts, errors and offline use with caching
Topics
- HTTP methods and status codes
- query parameters and API keys
- requests library
- error handling and timeouts
- caching responses to files
Lessons
-
Lesson 1 How Web APIs Work
Understand requests, responses, URLs, query parameters and status codes before writing client code.
endpointGET/POSTstatus codeAPI key
-
Lesson 2 Calling APIs with requests
Write Python code that requests data, checks the response and extracts the needed fields.
requests.getparamsresponse.json()raise_for_status()
-
Lesson 3 Reliable API Clients for Low-Bandwidth Conditions
Make API-based programs useful even when the connection is slow or drops, by retrying sensibly and caching results.
ConnectionErrorretry with backofflocal cachedata freshness
Practical activity
Build a 'daily rates board' script that fetches exchange rates once a day, caches them, and prints a formatted SSP/USD price table for a list of goods.
Expected outcomes
- Working API clients with proper error handling
- Programs designed for unreliable connectivity
Assessment
Live demonstration online and offline; code reviewed for timeouts, error handling and key management.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.