What is API testing? A practical guide for developers

An API test sends a real request to your API and checks the response: the status code, the headers, the body and how long it took. No browser, no clicking, no screenshots. Just "when I send this, do I get that?"

That simplicity is why API tests are usually the best value in a test suite. They run in milliseconds, they don't break when someone moves a button, and they test the contract your frontend, mobile app and partners actually depend on.

What API tests catch

Most API bugs fall into a few groups, and each one has a matching check:

BugWhat the test checks
The endpoint crashesStatus code is not 5xx
A field was renamed or removedThe body has the fields clients use
A field changed type ("42" instead of 42)Field types, or a JSON schema
Wrong data comes backSpecific values, such as the right user's ID
Someone can read data that isn't theirsA request with another user's token gets 403 or 404
It got slowResponse time is under a budget

UI tests can catch some of these, but slowly and indirectly. An API test catches them at the source, with an error message that says exactly what broke.

Your first API test

Take one request you already send by hand, for example GET /orders. Send it, look at the response, and write down what must be true:

JavaScript
pm.test('returns 200', () => {
  pm.response.to.have.status(200);
});

pm.test('returns a list of orders', () => {
  const body = pm.response.json();
  pm.expect(body.data).to.be.an('array');
});

pm.test('responds in under 500 ms', () => {
  pm.expect(pm.response.responseTime).to.be.below(500);
});

In Requestarium, that script goes in the request's Scripts tab as a post-response script. Every time you click Send, the tests run and the results show next to the response.

A request sent against a local environment with three passing tests next to the response
Each pm.test shows up as a result next to the response

The four kinds of checks

  1. Status. The quickest signal. Check the exact code you expect (201 for a create, not "any 2xx").
  2. Shape. The fields exist and have the right types. A JSON schema checks a whole response in one go.
  3. Values. The things that matter for this request: the ID you asked for, the total you expect, the status after an update.
  4. Speed. A response-time budget. Slow is a bug too, just a quieter one.

Test the unhappy paths

The happy path is the one you test by hand anyway. The bugs live elsewhere. For each important endpoint, add a few requests that should fail, and check that they fail properly:

  • no token, or an expired one → 401;
  • another user's resource → 403 or 404;
  • missing or invalid fields → 400 or 422 with a useful error;
  • an ID that doesn't exist → 404.

Negative testing for APIs goes through these in detail, and data-driven tests let one request cover many inputs.

From one request to a suite

A single test is useful. A collection of them is a safety net:

  1. Group requests into a collection, in the order a user would call them: log in, create, read, update, delete.
  2. Pass values between requests. The login stores a token; the create stores an ID for the next requests. See How to chain API requests.
  3. Use environments so the same collection runs against local, staging and production. See How to set up API environments.
  4. Run the whole collection from its Runs tab, or from a terminal:
Terminal
requestarium run-collection "Orders API" --env Staging
A collection run with every request passing
One click runs every request in order, with its tests

Run it on every change

Tests nobody runs don't protect anything. The CLI exits with a non-zero code when a test fails, so any CI system can use it as a gate:

Terminal
requestarium run-collection "Orders API" --env Staging --junit results.xml

Ready-made setups: GitHub Actions, GitLab CI, Jenkins.

Where to start

Don't try to test everything at once. Pick the five requests that would hurt most if they broke (login, checkout, whatever pays the bills), give each one a status check and a shape check, and run them in CI. Add a test every time a bug gets through. In a few months you'll have the suite you wish you had started with.