Skip to content

What is API testing?

Mikhail Bodnarchuk

Definition

API testing checks an application programming interface directly, without a user interface. A test sends requests to endpoints and verifies the status code, headers, response body and side effects. It covers correct behavior, error handling, authentication and authorization, and runs much faster and more reliably than checking the same rules through a browser.

What does an API test check?

An API test skips the screen and talks to the service the way another program would. It sends one request and checks everything the caller depends on. A thorough test looks at seven things:

CheckExampleWhere the rule comes from
Status code201 after a create, 422 for invalid inputHTTP semantics, RFC 9110
HeadersLocation points to the new resource; correct Content-TypeRFC 9110
Body shapeRequired fields present with the right typesYour API description, often an OpenAPI document
Body valuesOnly the values you control, such as the SKU you sentYour requirements
Error formatA machine-readable error, not an HTML stack traceProblem details, RFC 9457
Access controlNo token gets 401; another user's object is not returnedOWASP API Security Top 10
Side effectsThe record is stored, the event is published, nothing happens twiceYour requirements

Two of these deserve a closer look. RFC 9110 (June 2022) defines a method as idempotent when "the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request", and names PUT, DELETE and the safe methods. Retrying clients rely on that, so send those requests twice in a test and check that nothing doubles. RFC 9457 (July 2023) gives errors a standard JSON format with the application/problem+json media type, which a test can assert as exactly as a success response.

The OpenAPI Specification is at version 3.2.1, published on 10 September 2026. If your API has an OpenAPI document, validate responses against it in tests, so the documentation and the service cannot drift apart unnoticed.

What types of API testing are there?

  • Functional tests check that each endpoint does its job and rejects bad input.
  • Contract tests check that a provider still gives each consumer the fields and formats that consumer relies on.
  • Security tests probe authentication, authorization and abuse. The current OWASP list is still the 2023 edition (the OWASP API Security Project page lists "Latest Version 2023"), and it opens with broken object level authorization: endpoints that take an object ID and return it without checking who is asking.
  • Performance and load tests measure latency and throughput under expected and peak traffic.
  • Integration tests call the API together with its real database, queue or downstream services.

Most teams start with functional and access-control tests, because they catch the bugs users and attackers find first.

Example: API tests with Playwright

Playwright is best known for browsers, but it ships an HTTP client for API tests. Its docs describe a built-in request fixture "that respects configuration options like baseURL or extraHTTPHeaders" (Playwright API testing). The API under test is a small orders service on Node.js, started by Playwright's webServer option:

// playwright.config.js
import { defineConfig } from '@playwright/test'

export default defineConfig({
  testDir: './tests',
  reporter: 'list',
  use: { baseURL: 'http://localhost:3124' },
  webServer: { command: 'node api.js', url: 'http://localhost:3124/health' },
})

The tests, in tests/orders.spec.js:

import { test, expect } from '@playwright/test'

const as = (token) => ({ headers: { Authorization: `Bearer ${token}` } })

test('creates an order and returns it with a Location header', async ({ request }) => {
  const res = await request.post('/orders', { ...as('token-ana'), data: { sku: 'BEANS-1KG', qty: 2 } })
  expect(res.status()).toBe(201)
  expect(res.headers()['location']).toMatch(/^\/orders\/\w+$/)
  expect(await res.json()).toMatchObject({ sku: 'BEANS-1KG', qty: 2, status: 'new' })
})

test('rejects an invalid quantity with problem details', async ({ request }) => {
  const res = await request.post('/orders', { ...as('token-ana'), data: { sku: 'BEANS-1KG', qty: 0 } })
  expect(res.status()).toBe(422)
  expect(res.headers()['content-type']).toBe('application/problem+json')
  expect(await res.json()).toMatchObject({ status: 422, title: 'Invalid order' })
})

test('requires a token', async ({ request }) => {
  const res = await request.get('/orders/1')
  expect(res.status()).toBe(401)
})

test("does not show one user's order to another", async ({ request }) => {
  const created = await request.post('/orders', { ...as('token-ana'), data: { sku: 'MUG', qty: 1 } })
  const { id } = await created.json()
  expect((await request.get(`/orders/${id}`, as('token-ana'))).status()).toBe(200)
  expect((await request.get(`/orders/${id}`, as('token-ben'))).status()).toBe(404)
})

Run on 2026-11-19, @playwright/test 1.65.1, Node.js 22.23.5, no browser needed:

Running 4 tests using 1 worker

  ✓  1 tests/orders.spec.js:5:1 › creates an order and returns it with a Location header (42ms)
  ✓  2 tests/orders.spec.js:12:1 › rejects an invalid quantity with problem details (9ms)
  ✓  3 tests/orders.spec.js:19:1 › requires a token (7ms)
  ✓  4 tests/orders.spec.js:24:1 › does not show one user's order to another (11ms)

  4 passed (536ms)

To see the last test earn its place, we removed the owner check from the service's GET handler, the kind of one-line slip behind broken object level authorization. Three tests stayed green. The fourth failed with Expected: 404, Received: 200: Ben could read Ana's order. A suite of happy-path tests would never notice.

The four tests take about half a second. The same checks through a browser would need pages, forms and logins for two users.

If you write tests in CodeceptJS, its REST and JSONResponse helpers do the same job in a declarative style, with Zod for schema checks. Its docs give advice that applies to any tool: check only the invariable parts of responses, and avoid asserting id or date fields that change on every run (CodeceptJS API testing).

How is API testing different from UI and end-to-end testing?

API testUI testEnd-to-end test
Entry pointHTTP requestBrowser screenBrowser screen, then checks behind it
SpeedMilliseconds (7 to 42 ms each in our run)Slower: a browser loads and renders every pageSlowest: a browser plus every backend step (806 ms for a one-page checkout we tested)
FindsWrong status, missing field, broken access rulesLayout and interaction bugsBroken business transactions
Breaks whenThe API contract changesMarkup changesAny layer changes

API tests are the layer where business rules and access rules get most of their coverage. Keep browser tests for what only a browser can show.

What should you check before trusting an API test suite?

  1. Negative cases outnumber happy paths. For each endpoint: missing fields, wrong types, oversized input, no token, expired token, another user's object.
  2. Every role and object pair is covered. Build a small matrix of who may read and change what, and turn each cell into a test.
  3. Tests create their own data. Shared fixtures make tests depend on run order.
  4. The suite runs against a deployed environment too. Gateways, TLS and CORS settings only exist there; OWASP lists security misconfiguration as API8:2023.
  5. Responses are validated against the API description, so a renamed field fails a test before it fails a partner.

Our QA and test automation team writes REST, SOAP and GraphQL tests that check services directly. If your APIs now serve AI agents as well as people, read are your APIs ready for AI agents.

Sources

  1. RFC 9110: HTTP Semantics, IETF, 2022-06
  2. RFC 9457: Problem Details for HTTP APIs, IETF, 2023-07
  3. OpenAPI Specification v3.2.1, OpenAPI Initiative (Linux Foundation), 2026-09-10
  4. OWASP Top 10 API Security Risks 2023, OWASP, 2023
  5. OWASP API Security Project, OWASP, 2026-11
  6. API testing, Playwright docs (Microsoft), 2026-11
  7. API Testing, CodeceptJS docs, 2026-11

Frequently asked questions

Is API testing manual or automated?

Both exist, but automation is the norm. Manual calls in a tool like curl or an HTTP client help while exploring a new endpoint; once you know what the endpoint should do, turn those calls into automated tests that run in CI.

Do you need to know how to code for API testing?

Some scripting helps. Tests are short programs that build a request and compare the response, so basic JavaScript, Python or Java goes a long way, and readable frameworks keep the tests reviewable by the whole team.

What is the difference between API testing and unit testing?

A unit test calls a function inside the code. An API test calls the running service over HTTP, so it also covers routing, serialization, authentication and the database behind the endpoint.

What is API security testing?

It is API testing aimed at abuse rather than normal use: missing or forged tokens, access to other users' objects, oversized requests and calls in an unexpected order. The OWASP API Security Top 10 is the usual checklist to start from.

Building with AI agents? Talk to an engineer.