# What is API testing? What to check, types and a tested example

URL: https://sdclabs.com/glossary/api-testing/

> API testing sends requests to endpoints and checks status, headers, body and access rules. What to test, the main types, and a tested Playwright example.

# What is API testing?

[Mikhail Bodnarchuk](https://sdclabs.com/author/bodnarchuk/) 2026-11-23

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:

| Check | Example | Where the rule comes from |
|---|---|---|
| Status code | 201 after a create, 422 for invalid input | HTTP semantics, [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110) |
| Headers | Location points to the new resource; correct Content-Type | RFC 9110 |
| Body shape | Required fields present with the right types | Your API description, often an [OpenAPI](https://spec.openapis.org/oas/latest.html) document |
| Body values | Only the values you control, such as the SKU you sent | Your requirements |
| Error format | A machine-readable error, not an HTML stack trace | Problem details, [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) |
| Access control | No token gets 401; another user's object is not returned | [OWASP API Security Top 10](https://owasp.org/API-Security/editions/2023/en/0x11-t10/) |
| Side effects | The record is stored, the event is published, nothing happens twice | Your 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](https://owasp.org/www-project-api-security/) 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](https://playwright.dev/docs/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](https://codecept.io/api/) ).

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

|   | API test | UI test | [End-to-end test](https://sdclabs.com/glossary/end-to-end-testing/) |
|---|---|---|---|
| Entry point | HTTP request | Browser screen | Browser screen, then checks behind it |
| Speed | Milliseconds (7 to 42 ms each in our run) | Slower: a browser loads and renders every page | Slowest: a browser plus every backend step (806 ms for a one-page checkout we tested) |
| Finds | Wrong status, missing field, broken access rules | Layout and interaction bugs | Broken business transactions |
| Breaks when | The API contract changes | Markup changes | Any 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.
1. **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.
1. **Tests create their own data.** Shared fixtures make tests depend on run order.
1. **The suite runs against a deployed environment too.** Gateways, TLS and CORS settings only exist there; OWASP lists security misconfiguration as API8:2023.
1. **Responses are validated against the API description,** so a renamed field fails a test before it fails a partner.

Our [QA and test automation](https://sdclabs.com/services/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](https://sdclabs.com/blog/api-integration-ai-agents/) .

## Sources

1. [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110) , IETF, 2022-06
1. [RFC 9457: Problem Details for HTTP APIs](https://www.rfc-editor.org/rfc/rfc9457) , IETF, 2023-07
1. [OpenAPI Specification v3.2.1](https://spec.openapis.org/oas/latest.html) , OpenAPI Initiative (Linux Foundation), 2026-09-10
1. [OWASP Top 10 API Security Risks 2023](https://owasp.org/API-Security/editions/2023/en/0x11-t10/) , OWASP, 2023
1. [OWASP API Security Project](https://owasp.org/www-project-api-security/) , OWASP, 2026-11
1. [API testing](https://playwright.dev/docs/api-testing) , Playwright docs (Microsoft), 2026-11
1. [API Testing](https://codecept.io/api/) , 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.

Services

- [QA and test automation](https://sdclabs.com/services/qa-and-test-automation/)
- [API & Integration Services](https://sdclabs.com/services/api-integration/)

Read next

- [Are your APIs ready to be called by AI agents?](https://sdclabs.com/blog/api-integration-ai-agents/)
- [What is test automation? A guide from the founders of Codeception and CodeceptJS](https://sdclabs.com/blog/what-is-test-automation/)

Related terms

- [End-to-end testing](https://sdclabs.com/glossary/end-to-end-testing/)
- [Regression testing](https://sdclabs.com/glossary/regression-testing/)

[Mikhail Bodnarchuk](https://sdclabs.com/author/bodnarchuk/) Founder of Codeception and CodeceptJSBoth are open-source testing frameworks: Codeception for PHP, CodeceptJS for JavaScript.[LinkedIn](https://www.linkedin.com/in/davert/) [GitHub](https://github.com/DavertMik)

## Building with AI agents? Talk to an engineer.

[Start a project](https://sdclabs.com/contact/) [Book a call with the CEO](https://calendly.com/sdclabs/60min)
