What Is API Testing? A Practical Guide

API testing sends requests straight to an API and checks the response. What it is, the five types, multi-step flows, how to write tests and run them in CI.

Mustafa BayramogluMustafa BayramogluAbstract illustration of one request branching into five thin paths

API testing means sending a request straight to an API’s endpoint and checking what comes back, without a browser or a mobile screen in the loop. A test picks an HTTP method, points it at an endpoint, and checks the status code and the response body. That one mechanic covers five commonly cited types: functional, integration, load, security, and contract testing. This guide covers the definition with a real example, the five types, single requests vs multi-step flows, the four ways to write tests, running them on every pull request, keeping them current, and picking a tool.

What API testing is

API testing checks an API directly: a test sends a request to an endpoint and inspects the response. Nothing gets clicked, and no page gets built.

The category’s top guides agree on the core idea. Postman calls it a process that confirms an API is working as expected. IBM calls it verifying that an API functions as intended.

The tool is not the definition. Opening a client, building a request by hand and clicking Send is one way to check an endpoint. The same check can run from a command line, a CI job, or a generated suite that never opens a graphical client at all. What makes it API testing is where the check happens: at the interface, before any screen is built from it.

That placement is why teams reach for it early. An API is usually built before the interface on top of it, so testing it directly finds logic bugs before the UI work starts. And with no page to load and no browser to drive, one check finishes fast enough to run many of them on every change.

An example: one request, two checks

Here is a test in plain JavaScript with the built-in fetch and Node’s test runner. It creates an order and checks the answer:

import { test } from 'node:test';
import assert from 'node:assert/strict';

test('POST /api/orders creates an order', async () => {
  const res = await fetch(`${process.env.APP_URL}/api/orders`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${process.env.TEST_TOKEN}`,
    },
    body: JSON.stringify({ productId: 42, quantity: 1 }),
  });

  assert.equal(res.status, 201);
  const order = await res.json();
  assert.equal(order.productId, 42);
});

The first assertion checks the status code. A 201 means the request succeeded and a new resource was created. The second checks the payload: the order that came back is for the product that was asked for. Every API test is some version of this. Send a request, check the status, check the body.

Where API testing sits next to unit tests and end-to-end tests

An API test sits between a unit test and an end-to-end test. It runs a real request against a real, running service, but it skips the interface.

A unit test checks one function or class by itself, with everything around it faked. An end-to-end test drives the whole system the way a person would, through a browser, a mobile app or a form. An API test costs more than a unit test and less than a full end-to-end run; Integration Testing Examples for a REST API walks through four of them from request to assertion.

None of these layers replaces another. A passing API test says nothing about whether the sign-up form displays correctly, which is why the end-to-end testing guide keeps a few browser tests on top. A passing unit suite can hide an API bug, too. In one experiment, 2,189 unit tests and one API flow test ran against 8 ordinary bugs: the unit tests caught 5, the flow caught 6, and each caught something the other missed. See the unit test experiment for every row, and unit tests vs integration tests for when to write which.

The five types of API testing

The five types are functional, integration, load, security and contract testing. Each one asks a different question about the same endpoint.

Functional testing. Does the endpoint return the right data under normal conditions? Send a valid request, and confirm the response matches what the API promises. This is usually the first type a team writes, because it maps onto “does the feature work.” If you want to start without writing code, see testing an API without code.

Integration testing. Does the API work with the database, services and third-party systems behind it? A function can pass on its own and break the moment it calls a real neighbor. This type catches a change on one side of a connection before it reaches the other.

Load testing. Does the API stay fast and stay up under heavy traffic? Many virtual users run the same requests at once while the test tracks response times and errors. The guide to load testing with realistic, multi-step flows covers why a single-endpoint load test misses what a real user journey finds. For the full picture, see the practical guide to load testing an API.

Security testing. Do authentication, authorization and data handling hold up under input built to break them? This type asks the API to fail safely, with a 401 or a 403, and never to fail open. A functional check, built around valid input, has no reason to try.

Contract testing. Does the shape of each request and response still match the agreed schema as both sides change? It lets two teams change their own service without breaking the other’s. It runs against the schema, not a live service, so it is fast enough for every change. Martin Fowler describes contract tests as the way to check that a test double is faithful to the real service. See contract testing tools for microservices.

These five overlap. Most suites mix many functional checks with fewer load, security and contract checks. A new API usually gets functional coverage first and adds the others as its traffic and its number of clients grow. Some lists count nine or more types. A longer list usually splits this same handful into finer pieces.

How an API test runs, step by step

A single API test follows the same shape whatever its type. Here is one run, from start to finish.

Send the request. The test picks an HTTP method: GET to read, POST to create, PUT or PATCH to update, DELETE to remove. It sends it to an endpoint with the headers, auth and body that endpoint expects. A security test and a functional test can send the exact same request and differ only in what they check.

Check the status code. The test checks the code matches what the request should produce. The MDN status code reference lists them all. 200 means the request succeeded. 401 means the client must authenticate itself to get the response. 400 means the server rejected the request, and 500 means the server failed on its own side. A test that only checks “something came back” misses the difference between a real success and a quiet failure.

Check the payload. The test reads the response body, usually JSON, and confirms the fields, values and structure. A status code of 200 with the wrong data inside is still a bug. A renamed field, a missing item or a value in the wrong format all pass the status check and fail this one.

Check the timing, when it matters. Some tests also record how long the response took. That is the same request with a clock on it, and the same mechanic a load test runs at a much larger scale.

Read the result. A pass means every assertion held. A fail means at least one did not, and a useful test reports which one, so the fix targets the broken piece. That loop of request, assertion and result is what every tool in this category automates.

Single requests vs multi-step flows

A single-endpoint test checks one request on its own. A flow test chains requests the way a real client does, passing tokens and IDs from one response to the next request.

Real use is a sequence. A client logs in, keeps the token, creates an order, reads the order’s ID from the response, then pays for that order. Each step depends on the one before it. A test of POST /api/orders with a hard-coded token can pass while the real login returns the token under a new name and every real client breaks.

A flow test catches that kind of bug because it reads values from real responses:

- request:
    name: Login
    method: POST
    url: '{{ #env:APP_URL }}/api/auth/login'
    body: { email: '{{ #env:TEST_EMAIL }}', password: '{{ #env:TEST_PASSWORD }}' }
    assertions:
      - response.status == 200
- request:
    name: CreateOrder
    depends_on: Login
    method: POST
    url: '{{ #env:APP_URL }}/api/orders'
    headers: { Authorization: 'Bearer {{ Login.response.body.token }}' }
    body: { productId: 42, quantity: 1 }
    assertions:
      - response.status == 201

If the login stops returning token, the second step goes out without a valid token and fails. The same idea covers IDs: create a record, read its ID, and use it in the next call. The guide to multi-step API flows with auth tokens covers capturing a token, reusing it, and testing that an expired one gets rejected.

Use single-endpoint tests for edge cases on one route, such as bad input, missing fields or limits. Use flows for the journeys your users take.

Four ways to write API tests

You can write API tests by hand, generate them from an OpenAPI spec, record them from real traffic, or have AI generate them. Each path trades setup cost for a different kind of coverage.

By hand. You write each request and assertion yourself, in code or in a collection-based client. You get full control, and you also own every update when the API changes. A hand-written collection is a snapshot of the API on the day someone wrote it. See alternatives to hand-writing Postman collections.

From an OpenAPI spec. A tool reads your spec and creates requests for each endpoint, checking that responses match the schema. It covers every documented route quickly. It only knows what the spec says, so it can’t tell which calls clients chain together, and it can’t see routes the spec leaves out. See turning an OpenAPI spec into contract tests.

From recorded traffic. A tool captures real requests while someone uses the app, then turns them into tests. The tests follow real journeys, with tokens and IDs passed between steps. They only cover what someone did while recording, so a route nobody touched gets no test. For a code-based alternative, see Playwright API Testing vs a Recorded Flow. See API tests from real traffic, compared.

Generated by AI. A model reads a spec, a collection or your code and writes tests. It’s fast for a first draft. Read what it writes before you trust it, since a generated test can check the wrong thing with confidence. See AI tools for API test generation and Keploy vs Postman for AI-generated tests.

Most teams mix paths: generated or recorded tests for breadth, and a few hand-written ones for the edge cases that matter most.

Manual vs automated API testing

Manual API testing means a person sends requests and reads the answers. Automated API testing means code or a tool sends them and checks the answers on its own, every time something changes.

Manual testing is how most people start. You open a client, send a request, and look at the JSON. It’s the fastest way to learn a new endpoint or check a fix once. It doesn’t scale: nobody re-sends two hundred requests by hand before every merge, so the checks that matter stop happening.

Automated tests are the same requests with the looking written down as assertions. Once they exist, they run in seconds, the same way every time, and a machine reads the results. That’s what makes it possible to run them on every pull request.

A good split: try things by hand, and keep them as automated tests. When you find a bug manually, turn the request that showed it into an automated test, so the same bug can’t come back without a red check.

What to automate first

Automate the journeys that would hurt most if they broke, then widen. A small set of tests on the right routes beats a large set on the easy ones.

Start with these, in order:

  1. Sign-up and login. If they break, nothing else matters. Check the status, and check that the token or session comes back where clients expect it.
  2. The main money or data path. Checkout, booking, posting, saving: whatever your users came for. Test it as a flow, with each step using the previous step’s response.
  3. Permissions. Call a protected route with no token, and with another user’s token. Expect a 401 or a 403, never a 200.
  4. Routes other teams or apps depend on. A mobile app or a partner can’t ship a fix the day you rename a field. Contract checks on these routes pay off first.
  5. Bugs you already shipped once. Every fixed bug gets a test that would have caught it.

Then add edge cases on single endpoints: bad input, missing fields, limits, empty lists. Leave load and deep security checks for later, once the basics run on every pull request. For the full ranking and how to widen from there, see API automation testing: what to automate first.

Running API tests on every pull request

A test that only runs on someone’s laptop protects nothing. API tests earn their keep when they run automatically on every pull request, before the change merges.

In GitHub Actions, that means a workflow with the pull_request trigger that starts the app, runs the suite and reports a check. Make the check required, and a pull request that breaks an API test can’t merge. A working workflow file is in running API tests on every pull request.

Not every type belongs on every pull request. Functional, integration and contract checks are fast enough to run on each change. Large load tests and deep security scans usually run on a slower schedule, before a release.

Keeping API tests current

API tests go stale as the API changes. A renamed field, a new required parameter or a moved route breaks old tests, or worse, leaves them passing against behavior nobody uses anymore.

Three habits slow the drift. Put the tests in the same repo as the API, so a change and its test update land in one pull request. Regenerate generated tests when the source changes, whether that’s the spec or a new recording. And read every test update in review the way you read code, since a test that was changed to pass can hide a real break. The guide to keeping API tests current with code changes covers the mechanisms in detail.

Choosing an API testing tool

Pick a tool by how you want to write tests and where they need to run. A client for trying endpoints by hand is a different job from a suite that runs in CI.

Ask four questions. Where do tests come from: written by hand, a spec, recorded traffic, or AI? Do they live in your repo as files you can review? Can they chain steps, passing tokens and IDs? Do they run in CI on every pull request, with a clear report of which step failed? The roundup of API testing tools, Postman and six alternatives compares the common options on what each does best and how each runs in CI.

Stresseur sits on the recorded-traffic path. It records how your API is used during development, turns those flows into YAML tests, and runs them in CI on every pull request, showing which flow and which step got slower. Flows live in your repo under api-tests/. It doesn’t update tests on its own: it posts checks, comments and answers, and code changes stay with people. See automated API testing from real traffic for how it works, or the Stresseur docs.

API testing checks an API at the request and response level, before any screen is built on top of it. Every test does the same thing: send a request, check the status code, check the body. Start with functional checks on your main routes, then chain them into flows that follow real journeys. Run them on every pull request, and keep them in the repo next to the code they test. Add load, security and contract checks as your traffic and your number of clients grow.

Frequently asked questions

What is API testing with an example?

A test sends a GET request to an endpoint, then checks the status code and the response body. If the endpoint should return 200 with a user record, the test confirms both the 200 and that the fields and values in the body match what was asked for, because a 200 with the wrong data inside is still a bug.

Does API testing require coding?

Not necessarily. The same check can run from a command line, a CI job, or a generated suite that never opens a graphical client, and a request built by hand in a client is also API testing. What makes it API testing is where the check happens, at the interface, not which tool sent the request.

What are the types of API testing?

Five types are commonly cited: functional, integration, load, security, and contract testing. Each is a different question asked about the same endpoint.

What are the three main types of API testing?

There is no single standard list of three. A practical three to start with is functional, integration and security testing: does the endpoint return the right data, does it work with the services around it, and does it stay safe under bad input. Load and contract testing make five.

Is Selenium used for API testing?

Not directly. Selenium WebDriver drives a browser and acts like a user, so it checks what the page shows, not the raw API response. Its [own docs](https://www.selenium.dev/documentation/test_practices/discouraged/http_response_codes/) say that capturing HTTP status codes needs a proxy. For API tests, use a tool that sends requests straight to the API.

How can I test an API?

Send a request to one endpoint, then check the status code and the fields in the response body. Then chain requests the way a client does, such as log in and use the token, and run those checks on every pull request so a change can't merge without them.

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

An API test sits between the two: it runs a real request against a real, running service but skips the interface, so it costs more than a unit test and less than a full end-to-end run.

All posts