Postman Introduction
What is Postman?
Postman is a popular tool for building, testing, and documenting APIs. It provides a user-friendly interface for sending HTTP requests and inspecting responses, without writing code.
Key Features
- Sending GET, POST, PUT, DELETE, and other HTTP requests.
- Organizing requests into Collections.
- Managing different Environments (e.g., Dev, QA, Production) with variables.
- Writing test scripts in JavaScript to automatically validate responses.
- Generating shareable API documentation.
Why Testers Like Postman
Its visual interface makes it easy to manually explore an API before writing automated tests, and its built-in scripting supports basic automated validation without a full test framework.
Sending and Checking Your First Request
- Create a new Collection, for example "User API", to hold related requests.
- Add a request, choose the method
GET, and enter a URL such as{{baseUrl}}/users/2. - Create an Environment named "QA" with a variable
baseUrlset to your test server's address, and select it from the environment dropdown. - Click Send and look at the status code, response time, headers and body.
- Open the Scripts area (labelled Tests in older versions) and add checks so the result is verified automatically every time.
Using {{baseUrl}} instead of a fixed address means the same collection can run against Dev, QA or staging just by switching environments.
Writing Test Scripts
Postman scripts are JavaScript and use the pm object. Each pm.test block appears as a separate pass or fail result.
pm.test("Status is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response is fast enough", function () {
pm.expect(pm.response.responseTime).to.be.below(800);
});
const body = pm.response.json();
pm.test("User has an email", function () {
pm.expect(body.data.email).to.include("@");
});
// save a value for the next request in the collection
pm.environment.set("userId", body.data.id);
A pre-request script runs before the request is sent. It is a good place to build a timestamp, generate test data, or fetch a token. Values saved with pm.environment.set can be used later as {{userId}}, which lets you chain create, read, update and delete requests into one flow.
Running Collections and Automating with Newman
The Collection Runner executes every request in order and shows an overview of passed and failed tests. You can also feed it a CSV or JSON data file so the same requests run with many inputs.
For continuous integration, Newman runs collections from the command line. Export the collection and environment, then:
npm install -g newman
newman run user-api.postman_collection.json \
-e qa.postman_environment.json \
-d users.csv \
--reporters cli,junit --reporter-junit-export results.xml
The JUnit report can be published by most CI tools, so a failing API check can block a build.
Habits That Keep Collections Reliable
- Keep secrets out of shared collections. Store tokens and passwords in environment variables, mark them as secret, and avoid putting real credentials in exported files.
- Do not hard-code IDs. Create the data in an earlier request and pass its ID through variables.
- Name requests clearly, such as "Create user, valid data", so reports are readable.
- Test negative cases too: missing fields, wrong types and unauthorised calls.
- Use folders inside collections to group requests by feature, and add a short description to each.
Postman is excellent for exploring and quick regression checks. When the suite grows large or needs complex logic, many teams move core tests into a code-based framework such as Rest Assured while keeping Postman for exploration.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.