Skip to content

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

diagram Diagram mermaid

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.

diagram API Test Flow mermaid
An API test builds a request, sends it, checks the response, and reports pass or 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 coffee

Was this page helpful?

Let us know how we did