Calling APIs from Code
Move from one-off requests to code you would ship: JavaScript and Python clients, retries, timeouts, secrets, caching and credit budgets.
Calling APIs from Code badgeComplete all 5 lessons to earn it. About 2.4 hours.
0 of 5 lessonsStart course
What you'll be able to do
- Call an API with fetch in Node and the browser, and with requests in Python
- Add timeouts and retry with exponential backoff only when it is safe
- Keep API keys on the server with environment variables and a small proxy
- Cache responses so repeat lookups cost nothing
- Budget credits and stay under rate limits
This course is one of three skill areas on exam APV-100, APIVerve Certified Developer: API Fundamentals: 10 of its 30 questions. See the full path
Syllabus
- Call an API with JavaScript fetchStart hereA fetch API JavaScript example that works in Node 18+ and the browser - async/await, checking res.ok and the JSON envelope, and a reusable helper.
- Call an API with Python requestsPython requests with an API key header - params vs json, raise_for_status, a reusable helper and a Session, plus where httpx fits in.
- Timeouts, retries and backoffRetry with exponential backoff in JavaScript and Python - timeouts with AbortController, which errors to retry, jitter, and stopping on a 429 for credits.
- Keep API keys secretHow to hide an API key in frontend code - env vars, .env and .gitignore, rotating a leaked key, and a small proxy in Express or a Cloudflare Worker.
- Caching and credit budgetsCache API responses in JavaScript and Python with a TTL, decide what never to cache, read remaining credits from headers, and batch lookups.