API Testing Fundamentals
What is API testing?
API testing validates a service at the HTTP interface level:
- requests and responses
- status codes and headers
- payload correctness (JSON shape)
- authentication/authorization
- error handling and rate limits
What to test (checklist)
- Status codes: 200/201/204, 400/401/403/404, 429, 5xx
- Response body: required keys, value types, constraints
- Contracts: backwards compatibility
- Auth: missing token, invalid token, role permissions
- Idempotency: repeated requests behave correctly
- Performance: basic response time budgets
Diagram: test levels around an API
graph TD A["Unit tests\n(request builders, validators)"] --> B["API tests\n(HTTP-level)"] B --> C["End-to-end tests\n(user workflows)"]
Tip
- Write API tests as deterministic as possible.
- Avoid relying on external services in CI.
Visualize it
An API test builds a request, sends it to the endpoint, and checks the response before reporting pass or fail.
flowchart LR A["Build request"] --> B["Send to endpoint"] B --> C["Receive response"] C --> D["Assert status code + body"] D --> E["Pass"] D --> F["Fail"]
🧪 Try It Yourself
Exercise 1 – Write a unittest TestCase
Exercise 2 – assertRaises
Exercise 3 – setUp and tearDown
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
