Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 30 ยท Getting Started

What is API testing?

Learn what API testing is, how it differs from UI testing, where it sits in the test pyramid, what to check in a response, and where Postman fits in.

An API (application programming interface) is the door that one piece of software uses to talk to another. When a mobile app loads your orders, when a web page saves a form, or when a payment service tells your shop that a charge succeeded, there is almost always an API request behind it. API testing means sending requests to that door directly and checking that the answers are correct, fast and safe.

You do not need a screen, a browser or a tapping robot to do this. You send a request, you read the response, and you decide whether it is what you expected. That simple loop is what this whole tutorial is about, and Postman is one of the most popular tools for running it, saving it, and repeating it automatically.

This lesson explains the big picture: why test at the API level, what exactly you check, and how manual exploring turns into an automated safety net. Real Postman screens come in later lessons. Here, the runnable examples are stand-ins: a tiny fake API written in plain JavaScript that lives in the editor, so you can practice the thinking without any server or account.

APIs versus user interface tests

A UI test drives the visible application: it opens a page, clicks a button, types into a field and looks at what appears. It tests everything at once (layout, scripts, network, server), which is its strength and its weakness. UI tests are slow, and they break whenever a button moves or a label changes.

An API test skips the screen. It speaks the same language the screen would speak to the server, usually HTTP with JSON bodies, and checks the reply. Because there is no browser to start and nothing to render, API tests are:

  • Fast. Hundreds of requests can run in seconds.
  • Stable. A redesign of the page does not break them.
  • Precise. When one fails, you know the problem is in the server's behavior, not in a slow animation or a misplaced element.
  • Early. You can test an API before any screen exists, and you can test rules (such as "a customer cannot see another customer's order") that the UI would never let you try.

API tests do not replace UI tests. They cover different risks, which is why teams combine layers.

Where API tests sit in the test pyramid

The test pyramid is a rule of thumb for how many tests to have at each level. Many small, fast tests at the bottom; fewer, broader, slower ones at the top.

The test pyramid

Unit tests Many. One function, no network.
API tests A good number. Real requests to the service.
UI tests Few. Whole user journeys in a browser.

The higher the layer, the slower and more fragile the test.

1 / 2

API tests are the middle layer, and for many teams the best return on effort. They exercise real routing, validation, authentication and database access, yet stay quick enough to run on every code change.

What do you check in a response?

An HTTP response has several parts, and a good API test looks at more than one of them.

Four things to check

Status code 200, 201, 400, 404, 500...
Body The right fields and values.
Headers Content-Type, caching, Location.
Timing Fast enough for users.
1 / 2
  • Status code. Does a successful creation return 201, a missing item 404, and invalid input 400 or 422? The meaning of each code is covered in HTTP and REST in ten minutes.
  • Body. Are the expected fields present, with the right types and values? Is anything there that should not be, such as a password hash?
  • Headers. Is Content-Type correct? Does a creation response include a Location header? Are caching and security headers set as promised?
  • Timing. A response that arrives correct but after ten seconds is still a bug.

The stand-in below is a miniature bookstore API: a plain function api(method, path, body) that returns a status, headers and a body, just like a real server would. Run it and read the responses the way you would read them in Postman.

JS A tiny in-memory API, called like a client would

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that the failure cases matter as much as the successes. GET /books/99 is not an error in your test; it is a request whose correct answer happens to be 404. A thorough API test suite checks that the API fails correctly.

Manual testing versus automated testing

Most people begin manually: type a URL into a tool, press Send, and look at the result. This is called exploratory testing, and it is the best way to learn how an API really behaves, find surprises and reproduce a bug a colleague reported.

The weakness of manual testing is that nobody repeats it. A check you did on Monday is not rerun on Friday after someone changes the code.

Automated API tests write down the same checks as code. Each one sends a request, asserts what must be true about the response, and reports pass or fail. A machine can then run all of them on every change, at night, or after every deployment. The usual path looks like this:

  1. Explore the API by hand and learn its shape.
  2. Save the useful requests so you can send them again.
  3. Add assertions so the tool decides pass or fail, not you.
  4. Run the whole set automatically, for example in a CI pipeline.

Where Postman fits

Postman is an application for building, sending and organizing HTTP requests. It covers all four steps above in one place: a graphical request builder for exploring, collections for saving requests, a scripting area where you write tests in JavaScript, a Collection Runner for repeating them, and a command-line companion called Newman for running them in automation.

Postman is a tool, not the idea. The skills here (reading status codes, designing good checks, thinking about failure and security) apply to any tool, and the same checks could be written in a programming language with a test framework. Postman's advantage is that it lowers the barrier: you can start with no code and add scripting when you need it.

The next stand-in shows what an assertion really is: a statement about the response that is either true or false. This version of the API has two deliberate bugs, so you can watch the checks catch them.

JS Checking status, body, headers and timing

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Four checks fail: the wrong status, a leaked field, the wrong content type and the missing header. A person glancing at the body might have noticed only that it "looks fine". Written checks do not get tired and do not miss the header. In Postman you will write the same kind of checks with pm.test, in Writing tests with pm.test and Chai.

Everything here is honest about its limits. The "API" above is just a JavaScript function, so there is no network, no real HTTP and no real server. What carries over to real life is the thinking: send a request, then verify the status, body, headers and timing.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why are API tests usually faster and more stable than UI tests?

    API tests talk straight to the server without rendering anything, so they run quickly and do not break when the layout or labels change.
  2. 2. A request for an item that does not exist correctly returns 404. How should a test treat that?

    A test passes when the response matches what is expected. For a missing item, the expected answer is 404, so checking it proves the API fails correctly.
  3. 3. Which of these is NOT one of the four basic things to check in a response?

    The basics are status code, body, headers and timing. The color of a button belongs to the user interface, not to the API.
  4. 4. What is the main weakness of purely manual API testing?

    Manual testing is great for exploring, but nobody reruns a manual check on every code change. Automated tests do.

Summary

  • API testing sends requests straight to a service and checks the responses, without a user interface.
  • API tests sit in the middle of the test pyramid: faster and steadier than UI tests, broader than unit tests.
  • A response check covers the status code, body, headers and timing, plus failure, security and sequence behavior.
  • Failure cases deserve tests too: correct errors are part of a correct API.
  • Manual testing explores; automated tests repeat the same checks on every change.
  • Postman covers the whole journey from exploring to saving, scripting, running and automating requests.
  • The examples in this lesson are stand-ins (plain JavaScript functions), not a real server.

Next: HTTP and REST in ten minutes.