API testing fundamentals

Status codes, auth flows (bearer/OAuth), idempotency, pagination, negative and boundary cases; schema validation against OpenAPI. Assert on contract, not exact payload snapshots.

About 21 min read3-question knowledge check

The mental model

API testing is testing the building below the paint. The UI is the paint — colours, buttons, layout. The API is the load-bearing structure — where the business logic, the money movement, the authorization, and the data validation actually live. Most bugs that matter are structural, and you can inspect the structure far faster and more reliably than the paint.

The analogy that sticks: a restaurant's order window versus the dining room. UI testing is watching a customer walk in, sit down, read the menu, and eat — slow, and a single flickering light distracts you from whether the food is right. API testing is standing at the kitchen pass and checking every order ticket and every plate directly: "ticket says no onions, plate has onions — reject." You test the contract between kitchen and customer without the walk, the sitting, or the lighting.

The one idea that reframes how juniors test APIs: **assert on the contract, not on a snapshot of the payload.** A brittle test says "the response equals this exact 40-field JSON blob." A good test says "status is 201, the id is a non-empty string, total is a number matching the items, and the schema validates." The first breaks every time a developer adds an optional field; the second only fails when something the client actually depends on changes. APIs live at the fast, stable middle of the test pyramid precisely because you can assert contract instead of pixels — so you get more coverage of real logic per second of runtime than any other layer.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision