Backend Development 7 min read

Using Postman for API Testing: Installation, Requests, Collections, Variables, Scripts, and Test Cases

This guide introduces Postman as a Chrome extension for API testing, covering installation, request composition, collections, environment and global variables, pre‑request and test scripts with code examples, and best practices for automating and validating HTTP responses.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Using Postman for API Testing: Installation, Requests, Collections, Variables, Scripts, and Test Cases

Postman is a Chrome extension (also available as a desktop app) that serves as a widely used tool for API testing, allowing users to send any type of HTTP request such as GET, POST, PUT, DELETE, etc., by simply filling in the URL, headers, and body.

Installation can be performed via the Chrome Web Store or by downloading the standalone Mac application.

When sending a request, the interface provides a dropdown to select the HTTP method (15 options available), a field for the request URL, options to add URL parameters as key‑value pairs, and sections for authentication, headers, body, pre‑request scripts, and test scripts. The response can be viewed in three formats: pretty (highlighted), raw (plain text), and preview.

Collections in Postman act like folders, enabling users to group related requests for a project, share them with teammates via the Share button, and run the entire collection with the Start Test button for automated or regression testing.

Environment variables allow quick switching between different environments (e.g., test and pre‑production) without modifying each request. Users can add or import variables through the Manage Environments dialog and reference them in requests using the {{variableName}} syntax.

Global variables are accessible across all environments and can be created either programmatically with postman.setGlobalVariable(name, value) or manually. Dynamic variables such as {{$timestamp}} and {{$randomInt}} provide runtime values for URLs, headers, or bodies.

Pre‑request scripts run JavaScript code before a request is sent. For example, to generate an MD5 signature:

var str = environment.variable_1 + environment.variable_2;
var hash = CryptoJS.MD5(str).toString();
postman.setEnvironmentVariable('hash', hash);

Test scripts execute after a response is received, enabling validation of status codes, response bodies, headers, response times, and more. Common examples include:

postman.setEnvironmentVariable("key", "value");
postman.getEnvironmentVariable("key");
tests["Body matches string"] = responseBody.has("string_you_want_to_search");
var jsonObject = xml2Json(responseBody);
tests["Response time is less than 200ms"] = responseTime < 200;
tests["Status code is 200"] = responseCode.code === 200;
tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");
var data = JSON.parse(responseBody);
tests["Your test name"] = data.value === 100;

The article concludes that Postman is a powerful and convenient tool for API testing, though many other frameworks exist; users should choose the tool that best fits their workflow.

Test scriptCollectionsAPI testingPostmanEnvironment VariablesPre-request Script
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.