Master Postman: Essential Features and Advanced Tips for API Testing
This comprehensive guide walks you through Postman's core capabilities—including installation, interface navigation, sending requests, handling query parameters, forms, JSON and file uploads, response analysis, collection management, batch execution, logging, assertions, variables, pre‑request scripts, and request chaining—empowering developers and testers to automate and streamline API testing workflows.
Overview
Postman is a powerful HTTP API debugging and testing tool that offers a rich set of features for developers and testers. It simplifies request creation, response inspection, test automation, and collaboration.
Installation
Postman no longer supports a browser version after 2018, so you must download the desktop client. For Windows, download the installer from the official website, run the installer, and follow the prompts to complete installation.
Interface Navigation
The main UI includes a request builder, method selector, URL bar, Params, Headers, Body, and a response pane with tabs for Pretty, Raw, and Preview. Additional panels provide access to Collections, Environments, and Logs.
Sending the First Request
Open Postman and click the "+" button to create a new request.
Enter the request URL, e.g., http://www.weather.com.cn/data/sk/101010100.html.
Select the HTTP method (GET by default) and click Send .
View the JSON response in the response pane.
Basic Functions
Common request types : query parameters, form‑encoded, JSON, multipart/form‑data (file upload).
Query parameters : add key‑value pairs in the Params tab or directly in the URL after ?.
Form requests : set Content‑Type: application/x-www-form-urlencoded and fill key‑value pairs in the Body → x‑www‑form‑urlencoded tab.
File upload : choose form‑data in Body, set the field type to File, and select a local file.
JSON requests : select raw → JSON in Body and paste the JSON payload.
POST http://localhost/index.php/home/Uploadify/imageUp/savepath/head_pic/pictitle/banner/dir/images.html HTTP/1.1
Content-Type: multipart/form-data
file=a1.jpgResponse Parsing
Postman displays the response in three tabs:
Pretty : formatted view (JSON, HTML, etc.).
Raw : raw response data.
Preview : renders HTML responses.
Collection Management (Collections)
Collections let you group related requests, organize them into folders (modules), and run them together. To create a collection, click New Collection , name it, add folders, and add requests inside each folder.
Batch Execution
Select a collection, click the three‑dot menu, and choose Run to open the Collection Runner. All requests in the collection are selected by default; click Run Collection to execute them sequentially.
Logging and Debugging
Use console.log("message") in Pre‑request Script or Tests to output logs. Open the Postman console via the menu or the bottom‑left icon to view logs, filter by level, and search for specific entries.
Assertions
Write JavaScript assertions in the Tests tab using the pm.test API. Common assertions include status code, response time, header presence, body content, and JSON value checks.
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Content-Type header is present", function () {
pm.response.to.have.header("Content-Type");
});
pm.test("Response body contains string", function () {
pm.expect(pm.response.text()).to.include("string_you_want_to_search");
});Variables (Global, Environment, Collection)
Variables store reusable values. Define them via the gear icon (Globals/Environments) or in a collection’s Variables tab. Use {{variableName}} in request fields, or access them in scripts with pm.globals.get, pm.environment.get, or pm.collectionVariables.get. Set them with pm.globals.set, pm.environment.set, or pm.collectionVariables.set.
// Set a variable
pm.environment.set("token", "abc123");
// Get a variable
var token = pm.environment.get("token");Pre‑request Scripts
Pre‑request scripts run before the request is sent. They are useful for generating dynamic data (e.g., timestamps, random numbers) or encrypting parameters.
var timestamp = Date.now();
pm.environment.set("ts", timestamp);Request Chaining (Interface Association)
Extract data from a response, store it in a variable, and use it in a subsequent request. Example: upload an avatar, capture the returned url, save it as a variable, and use that variable in the image preview request.
// Extract URL from previous response
var json = pm.response.json();
pm.environment.set("avatarUrl", json.url);Then reference {{avatarUrl}} in the next request’s URL.
Common Return Value Extraction
Use JavaScript dot notation and array indexing to retrieve nested JSON values.
// Example JSON
var json = pm.response.json();
var userId = json.data.user_id; // nested object
var secondPoint = json.data.roles.points[1]; // array index
var lastId = json.data.rows.slice(-1)[0].id; // last elementSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
