Backend Development 22 min read

Comprehensive Guide to Using Postman for API Testing and Automation

This article provides a detailed walkthrough of Postman, covering its core and advanced features, installation steps, interface navigation, how to send various types of requests, response analysis, collection management, batch execution, logging, assertions, variables, pre‑request scripts, request chaining, and techniques for extracting values from complex JSON responses.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Comprehensive Guide to Using Postman for API Testing and Automation

Postman is a powerful HTTP‑based API debugging and testing tool that offers a wide range of basic, convenient, and advanced functionalities. The article begins with an overview of its features and proceeds to describe three main dimensions: basic functions (common request types, response parsing, collection management), convenience features (quick parameter filling, header shortcuts, batch assertions), and advanced capabilities (file upload, JSON requests, test report generation, mock services, monitoring, workspace usage, code synchronization, database connections, and API generation).

Installation : Since the browser version was discontinued after 2018, users must download the desktop client. Installation steps for Windows are outlined, including downloading from the official site, running the installer, and choosing between personal (skip login) or team (register) usage.

Interface Navigation : A screenshot‑based guide explains the main UI elements, helping new users locate request tabs, method selectors, URL fields, and other controls.

Sending the First Request : An example request to a weather API demonstrates how to open a new tab, enter the URL, and view the JSON response.

Basic Request Types :

Query parameters – set method to GET and enter the URL with parameters.

Form‑encoded requests – set method to POST, specify Content-Type: application/x-www-form-urlencoded , and provide key‑value pairs in the body.

File upload (multipart/form-data) – set method to POST, choose body → form‑data , select the file field type, and upload a file.

JSON requests – set method to POST, choose body → raw → JSON , and paste the JSON payload.

Response Parsing : The response panel displays the status line, headers, and body. Users can view the body in Pretty (formatted), Raw (unprocessed), or Preview (rendered HTML) modes, and use the Time and Size metrics for simple performance checks.

Collection Management : Collections allow grouping of requests for a system, with folders representing modules. Steps to create a collection, add folders, and add requests are illustrated.

Batch Execution : The Collection Runner enables running all selected requests, showing assertion statistics, run summary, export options, retry, and new run configuration.

Logging : Postman’s console (accessible via the menu or bottom‑right icon) displays script logs, searchable by keyword or log level, and can show raw network logs.

Assertions : Written in JavaScript within the Tests tab, assertions can verify status codes, headers, body content, JSON values, and response times. Example snippets include:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
pm.test("Body contains string", function () {
    pm.expect(pm.response.text()).to.include("string_you_want_to_search");
});

Variables : Global, environment, and collection variables store reusable values. They can be defined via the UI or programmatically (e.g., pm.environment.set("varName", value) ) and accessed using {{varName}} in request fields or pm.environment.get("varName") in scripts.

Pre‑request Scripts : JavaScript code executed before a request can generate random numbers, encrypt data, or set variables. A sample use case shows generating a random token and saving it as an environment variable.

Request Chaining (Interface Association) : The response value from one request (e.g., an uploaded image URL) can be saved to a variable and used in a subsequent request’s URL, enabling dependent API flows.

Extracting Values from Complex JSON :

Single nested value: var user_id = jsonData.data.user_id;

Array element: var point = jsonData.data.roles.points[1];

Last element of an array: var lastId = jsonData.data.rows.slice(-1)[0];

The article concludes with references to the author’s other technical columns and promotional links.

automationbackend developmentVariablesAPI TestingPostmanAssertions
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

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.