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

false


  graph TD
A[Unit tests\n(request builders, validators)] --> B[API tests\n(HTTP-level)]
B --> C[End-to-end tests\n(user workflows)]

false

Tip

  • Write API tests as deterministic as possible.
  • Avoid relying on external services in CI.

๐Ÿงช 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