Lesson 20 — API Testing Basics: Talking to the Machine Directly · Practical QA
LESSON VIEW
B-11 · BASIC · PRACTICAL QA

Lesson 20 — API Testing Basics: Talking to the Machine Directly

Objective: What an API test is, the status codes that matter, and the API test already hiding inside your UI suite.

⏱ ≈4 min full lesson · Converted from the B-11 module deck · English edition — Español · العربية · বাংলা in translation

⚡ Key Points

  • Requests without the browser — Under every page, the browser makes REQUESTS (“give me this page”, “here's the form data”) and gets RESPONSES with a STA…
  • The four codes that matter — 200 = OK, here's your answer. 301/302 = moved, follow me.
  • The API test inside TC-002 (real code) — Inside TC-002: ask cheaply first (HEAD = “just your status, not the whole page”), fall back if refused, then assert a RA…
  • The pyramid (preview) — Fast API and unit checks in bulk at the bottom; fewer slow UI journeys on top.
  • Plug & chug: meet a 404 — Visit any site, then break the address: add /this-page-does-not-exist.

📖 Read

In ~4 minutes: what an API test is, the status codes that matter, and the API test already hiding inside your UI suite.

Requests without the browser: Under every page, the browser makes REQUESTS (“give me this page”, “here's the form data”) and gets RESPONSES with a STATUS CODE attached. An API is programs making those requests without a browser. An API test: send a request, check the response. No screen involved.

The four codes that matter: 200 = OK, here's your answer. 301/302 = moved, follow me. 404 = not found — wrong address. 500 = server error — their machine broke answering. Four numbers cover most of testing life.

The API test inside TC-002 (real code): Inside TC-002: ask cheaply first (HEAD = “just your status, not the whole page”), fall back if refused, then assert a RANGE — anything under 400 is healthy, because redirects are fine too. Request → status → assertion: an API test in miniature. Code: const r = await fetch(target, { method: "HEAD" }); | if (r.status !== 405) status = r.status; | expect(status).toBeGreaterThan(0); | expect(status).toBeLessThan(400);

The pyramid (preview): Fast API and unit checks in bulk at the bottom; fewer slow UI journeys on top. That's the shape of healthy test portfolios — and API tests can check data and timing the UI never shows.

Plug & chug: meet a 404: Visit any site, then break the address: add /this-page-does-not-exist. The 404 you see is a status code made visible. You've been reading API results for years — now you have the name for them.

Machine-to-machine, handled. Next: visual testing — checking what things LOOK like.