Skip to content

Chapter 1 of 7

Foundations of API Testing

API testing is the practice of verifying that an application's interfaces behave correctly across functionality, contracts, performance, security, and error handling. It is valuable because it catches defects below the UI layer, runs faster than full end-to-end browser tests, and provides direct confidence in how services actually behave on the wire. Unlike unit tests, which isolate small pieces of logic, and integration tests, which verify components working together, API tests target the service boundary—the HTTP surface that clients actually call. Common categories include functional and contract checks, authentication and authorization checks, validation and error-handling checks, and performance and security tests.

A cornerstone concept is the contract, which describes the expected structure and behavior of requests and responses, including field names, types, and status codes. Good tests validate contracts explicitly: confirming that status codes communicate success or failure correctly, that response shapes contain required fields with the right types, and that error payloads are meaningful. Both happy-path tests—valid input under normal conditions—and negative tests, which probe invalid, unauthorized, malformed, or out-of-range input, are essential. Edge cases such as empty payloads, large inputs, missing fields, and duplicate requests warrant special attention because they are frequent sources of production bugs. A test oracle, such as a schema, a database state, or a business rule, is the source of truth against which outcomes are judged.

Disciplined setup and isolation keep a suite reliable. Data setup creates predictable preconditions, and fixtures provide stable known data that makes tests easier to read and less brittle. Test isolation ensures that no test depends on the execution order or side effects of another, while schema validation against JSON Schema or OpenAPI definitions catches structural drift automatically. Mocking external services reduces flakiness and clarifies failure causes. Because retries happen in real systems, idempotent endpoints reduce duplicate side effects—an important property to test for. Pagination, sorting, and filtering bugs often produce wrong results without obvious crashes, so they deserve coverage. Consumer-driven contract testing lets consumers record the expectations they rely on and providers verify them continuously, so contract drift is caught before it reaches production. Smoke tests provide lightweight post-deployment confirmation that core endpoints are reachable; regression tests ensure previously working behavior still works after code changes. A flaky test, which passes and fails unpredictably due to timing, shared state, or unstable dependencies, is a warning that underlying instability needs diagnosis rather than retries that hide the problem. Over the long term, a valuable suite stays fast, readable, isolated, and closely tied to the behaviors clients actually depend on.

All chapters
  1. 1Foundations of API Testing
  2. 2HTTP Status Codes and Communication
  3. 3HTTP Methods, Headers, and Request Formats
  4. 4Authentication, Authorization, and Browser Concerns
  5. 5API Architectural Styles and Security
  6. 6Contract Testing, Mocks, and Test Patterns
  7. 7Performance, Observability, and Operations

Drill it

Reading is not remembering. These come from the API Testing deck:

Q

What is API testing?

API testing verifies that an application's interfaces behave correctly in terms of functionality, contracts, performance, security, and error handling.

Q

Why is API testing valuable?

It catches issues below the UI layer, runs faster than end-to-end tests, and provides direct confidence in service behavior.

Q

What is the difference between unit, integration, and API tests?

Unit tests isolate small pieces of logic, integration tests verify components working together, and API tests validate behavior at the service boundary.

Q

What is a contract in API testing?

A contract describes the expected structure and behavior of requests and responses, including fields, types, and status codes.