API Quiz
Test your knowledge of HTTP methods, status codes, headers, and authentication.
Course Recap: REST APIs
Before you take the quiz, review the core concepts from this module. Every question below draws from these fundamentals.
REST API Architecture
REST (Representational State Transfer) is the most common architecture for web APIs. It organizes data into resources — things like users, orders, or products — each accessed through a URL. REST APIs are stateless: every request must contain all the information the server needs to process it. The server does not remember your previous requests.
/users, /orders/42, /products?category=books
GET /users and POST /users are different endpoints on the same path.
HTTP Methods
The four core methods map to CRUD operations (Create, Read, Update, Delete). Understanding which method to use and when is fundamental to working with any API.
Authentication Patterns
APIs need to know who is making the request. The three major authentication patterns each serve different use cases.
A secret string sent in every request header. Simple, fast, widely used. Best for server-to-server communication. Example: Authorization: Bearer sk_live_...
User grants your app permission via a login flow. You receive an access token that expires. Users can revoke access anytime. Best for apps acting on behalf of users.
A self-contained token carrying user identity and permissions. Server verifies it without a database lookup. Best for session management in modern web apps.
Error Handling
Robust error handling separates production-quality code from fragile scripts. Every API call can fail, and your code must handle each failure mode.
Rate Limiting
Every API limits how many requests you can make per time window. Understanding rate limits is critical for automation because your code can make thousands of requests faster than any human.
X-RateLimit-Limit (your max), X-RateLimit-Remaining (calls left), Retry-After (wait time after hitting the limit).
GET /users/1, GET /users/2, GET /users/3 separately, use GET /users?ids=1,2,3 if the API supports it.
time.sleep(0.1) adds only 100 seconds total but prevents rate limiting.
Common API Mistakes
These are the mistakes developers make most often when working with APIs. Avoid these and you will save hours of debugging.
API keys committed to Git end up in your repository history forever. Even if you delete them later, anyone with access to the repo can find them. Use environment variables or a secrets manager instead.
Without a timeout, your code will wait forever if the server stops responding. Always set an explicit timeout (10-30 seconds for most APIs). A hung request blocks your entire automation pipeline.
Most APIs return results in pages (20-100 items at a time). If you call GET /users and only read the first page, you are missing data. Check for next_page or has_more fields and loop until all pages are fetched.
Test API keys (sk_test_...) work in development but process fake data. Forgetting to switch to live keys (sk_live_...) before deployment means your production system does nothing real. Always verify your environment configuration before going live.
APIs can change their response format between versions. If you access response["data"]["users"] without checking that those keys exist, your code crashes when the structure changes. Always validate before accessing nested fields.
Status Code Decision Tree
When your API call returns an error, use this decision tree to diagnose and fix the issue systematically.
Quick Reference: Response Debugging
import httpx
response = httpx.get("https://api.example.com/users", headers={
"Authorization": "Bearer sk-your-key"
})
# Always print these when debugging
print(f"Status: {response.status_code}")
print(f"Headers: {dict(response.headers)}")
print(f"Body: {response.text[:500]}")
# Check rate limit headers
remaining = response.headers.get("X-RateLimit-Remaining")
if remaining:
print(f"Rate limit remaining: {remaining}")
# Handle different status codes
if response.status_code == 200:
data = response.json()
elif response.status_code == 429:
retry_after = response.headers.get("Retry-After", "60")
print(f"Rate limited. Retry after {retry_after}s")
else:
print(f"Error {response.status_code}: {response.text}")
This lesson is for Pro members
Unlock all 520+ lessons across 52 courses with Academy Pro.
Already a member? Sign in to access your lessons.