Featured image of post Postman Advanced Guide

Postman Advanced Guide

Advanced Cloud Features of Postman

Introduction

In our previous series, we detailed how to use Postman for API testing, covering basic functions, advanced scripting, and automation implementation. In our work, besides these local testing implementations, we often need to manage API test cases through the cloud and leverage cloud-based capabilities for enhanced testing due to different office locations or team collaboration requirements. In this article, we’ll explore the advanced Cloud services provided by Postman.

Introduction to Postman Cloud Services

To use Postman Cloud services, we first need to register an official account

image

After registration and login, you can access the Cloud management page by clicking the dashboard button in the upper right corner of the official homepage. This will display your workspaces, including your personal workspace and any team workspaces you’ve created for sharing.

image

Workspace and Cloud Feature Overview

A workspace is a management unit in Postman Cloud. Through cloud workspace synchronization, we can achieve several advantages that aren’t possible with the local application:

  • Convenient organization and management of personal work across different locations and devices. For example, you can continue unfinished work at home that you started at the office.

  • Facilitates team collaboration by sharing relevant metadata and team workspaces, allowing team members to jointly maintain the same set of interfaces and share work results.

  • A unified workspace enables teams to work in the same dimension, avoiding inconsistencies in work progress and data that could lead to misunderstandings and communication gaps.

  • The workspace history function helps record and trace interface operation records, making it convenient to save work processes and results.

The image below shows the interface after entering a workspace in the Cloud. You can see the functions provided by Postman Cloud. By default, it displays the Collection information in the current space. The other tabs are interface operation history, environment variables, monitoring tasks, Mock services, API integration capabilities, and workspace operation records.

image

Below are the History interface operation records and Activity workspace operation records:

image

image

Account System and Pricing

After registering on the Postman website, you have a free account by default, which can be upgraded to Professional or Enterprise versions. The current monthly fees are as follows:

image

The free version includes the following features. As you can see, most functions are supported, with the main difference being usage limits. Free accounts are limited to 1,000 online document views, Mock requests, API calls, and monitoring calls per month, which can generally meet individual learning and basic testing needs. For larger teams, it’s better to upgrade to a premium version or choose alternative solutions.

image

Local Application Login

In the Postman application, we can also log in with our registered account. After logging in, the banner at the top will display the default workspace and account avatar.

image

After logging in, the local app will automatically synchronize with the information saved in the cloud to maintain data consistency. Let’s now look at the services provided by Postman Cloud.

Postman Cloud’s Online API Documentation

Powerful and beautifully formatted online documentation is an important service of Postman Cloud. It has the following main advantages:

  • Support for Private and Public Documentation

When you register a Postman account, the online documentation feature is enabled by default. After logging into the web workspace and entering a Collection, you can see that the online documentation for the current Collection has been automatically generated, as shown:

image

The image above shows private documentation that only the current account can view in the workspace. Using the Share button in the upper right corner, you can share the current documentation with other workspaces or team workspaces. The Publish button allows you to publish the current documentation as public documentation for open access.

image

In the Postman app, you can also use the Publish Docs button in the Collection menu to publish public documentation. After publishing, a public access URL will be generated, through which the documentation can be accessed.

image

  • Automatic Documentation Generation

As mentioned above, Postman online documentation is automatically generated, eliminating the previously cumbersome document editing and formatting work. It can automatically generate the following content:

  • Request examples, including request method, URI, message content, headers, parameters, etc.
  • Interface response information saved as Examples
  • Descriptions written for Collections, Folders, and Requests
  • Automatically generated code snippets in various mainstream languages

The image below shows the Collection description editing interface: image

  • Support for Markdown Syntax

When writing Descriptions, we can use Markdown syntax, which further enhances the reading experience of the documentation. The image above includes Markdown list and bold syntax.

  • Support for ID-Based Internal Links

We can also use the unique IDs generated by Postman for each request and folder for cross-referencing within the documentation. When we click on the corresponding element in the right navigation bar of the document, the unique ID of that element is displayed in the URL, as shown:

image

Note: ID information can also be obtained through the Postman API interface.

  • Support for Automatic Generation of Code Snippets in Mainstream Languages

Another excellent feature of Postman online documentation is its support for code snippets in multiple mainstream languages, which is convenient for debugging code in the respective language. As shown: image

  • Support for Comments

In private documentation such as team spaces, we can also use the comment feature to communicate with team members and confirm information by annotating interfaces.

image

Postman Online Documentation Usage Limits

Postman Cloud limits the number of views for both private and public documentation. Free accounts have a monthly limit of 1,000 free views for each. This is barely sufficient for individual use and learning. For team collaboration, it’s definitely inadequate, so it’s recommended to choose a paid account or an open-source free alternative like Swagger.

Current usage can be viewed on the Resource Usage page of your personal account:

image

Introduction to Postman’s Mock Server

Another advanced feature of Postman Cloud is its support for Mock Servers.

In interface development and testing work, especially for software products developed in parallel by multiple teams such as frontend, backend, and app teams, a common situation is that progress often depends on other teams. For example, an app might depend on backend interfaces for debugging, or on interfaces provided by third-party teams. If the interfaces are not yet ready for joint debugging, to ensure development progress, mocking interfaces according to certain conventions becomes a necessary choice.

A Mock Server is a functional module that provides this service. In Postman, we can save responses as Examples, and then conveniently create Mock services based on these examples to simulate message responses independent of the original interface.

The image below shows a response Example saved in the Postman app. For the same interface request, we can save different response results as multiple different examples.

image

Creating a Mock Server

There are several ways to create a Mock Server in Postman:

  • Through the New button in the Postman app
  • In the launch window that automatically pops up when opening the Postman app
  • In the Collection menu
  • Through the Postman API

Here, we’ll use the Collection menu as an example. Select Mock Collection:

image

Set up the Mock Server based on the Collection information: image

Upon successful creation, an online Mock Server access URL will be generated, in this example: https://b0fadee4-7560-4b14-a201-599985ce4f0f.mock.pstmn.io

image

This completes the creation of the Mock service for the current Collection. Postman will default to creating an Environment with the same name as the current Collection, and in this environment, it will add a url variable with the value being the Mock service address just created.

image

Using the Mock Server

After creating the Mock service, we can simulate interface responses through the previously generated Mock service address. The image shows accessing an interface saved in the Mock service, which returns the content of the previously saved response Example.

image

Mock Server Matching Algorithm

At this point, you might wonder how the Mock Server determines which content to respond with based on the request, especially when we have saved multiple Examples for the same request. Let’s introduce the response matching algorithm used by the Mock Server.

The image below shows the algorithm sequence used by the Mock Server for response matching:

image

  1. First, it filters responses based on the format of the content to be responded with, such as JSON or XML format (based on the request format definition).

  2. It matches based on the HTTP method of the request, eliminating responses that don’t match the request’s HTTP method.

  3. It matches based on the URL path of the request. It prioritizes strictly matching paths, then multi-level paths with /, then paths ignoring case and ID information. If no match is found, it returns that no corresponding response was found.

  4. You can specify the response message by carrying a specified header value in the request message header. Postman supports carrying x-mock-response-name, x-mock-response-id, and x-mock-response-code in the message header, which can specify the response name (saved example name), the ID of the response Example (unique ID, which can be queried through the API), and the response status code, respectively.

  5. Among the remaining responses, they are sorted in reverse order of saving, and the one with the highest threshold is selected for response.

The image shows a Mock service for creating a Repo, with multiple response Examples. Here, it matches the request method and request path: image

The image below shows a request that includes a specified Header, x-mock-response-code, specifying to return a response with a status code of 422. image

As we can see, through Postman’s Mock Server service, we can simulate interface responses without relying on the original interface environment, to meet our business testing needs. Currently, free accounts have a monthly limit of 1,000 calls through the Mock Server.

Postman’s Monitoring Feature

Next, let’s introduce the monitoring service provided by Postman Cloud.

For internet applications, how do we ensure our business can correctly provide services? How do we prevent business interruptions due to service anomalies or network issues?

In the process of collaborating with external teams, if the other party’s interface changes, how can we be informed promptly to avoid a lot of wasted effort?

Due to these issues, the importance of monitoring interfaces is self-evident. Postman’s interface monitoring function is essentially a feature provided by the Cloud that schedules the execution of interface test tasks, records results, and sends notifications. You might say that this can also be achieved through CI integration tools like Jenkins.

Indeed, this effect can be achieved through CI scheduling, but Cloud monitoring can also provide the selection of different access regions and value-added capabilities such as trend visualization and analysis of monitoring results.

The image below shows selecting a new monitor from the Collection menu in the Postman app:

image

The image below shows creating a monitor in the Postman web workspace:

image

The images below show the created monitor and the monitoring results interface:

image

image

In addition to creating monitors through the App and the Cloud web interface, we can also create monitors through the Postman API.

Additionally, there are several limitations to Postman’s monitoring function that you should be aware of:

  • Since monitoring is executed in the cloud, the monitored interface needs to be accessible via the internet. For interfaces developed on an intranet, a public access interface needs to be exposed.

  • Postman currently doesn’t have a file storage function, so it doesn’t support attaching files in interface requests.

  • Similarly, it doesn’t support using data files to provide data variables.

  • The interface execution record doesn’t record the request and response message bodies.

  • Currently, free accounts have a monitor interface execution limit of 1,000 times per month.

Postman’s Open API

Besides creating and managing Collections, Environments, Mock Servers, Monitors, etc. through the Postman App and the cloud web interface, Postman Cloud also provides its own API interfaces, making it convenient for users to call from their own tools or scripts, and more easily schedule and manage the related services provided by Postman.

Postman’s API is provided through cloud-based Integration. (For professional and higher accounts, other integrated third-party tools are also available.)

image

Obtaining Authentication Code

To use the Postman API, you first need to generate an authentication code. Enter from the interface shown above, select Get API Key:

image

After generation, you can view the current Key value in Existing API Keys:

image

There are two ways to use the authentication code for the Postman API:

  1. By adding an X-Api-Key header in the request message to carry this key value for authentication.

  2. By carrying the query parameter apikey in the request URL, such as:

1
https://api.getpostman.com/collections?apikey={{postman_api_key}}

If you don’t carry the authentication code, the interface will return the following error:

1
2
3
4
5
6
{
    "error": {
        "name": "AuthenticationError",
        "message": "Invalid API Key. Every request requires a valid API Key to be sent."
    }
}

Access Frequency Limits

Similar to most RESTful API services, to prevent DDOS attacks, Postman API also limits the frequency of interface access to no more than 60 times per minute. In the response message, you can learn about this limit, remaining count, and reset time through custom headers such as X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset. As shown in the interface below for getting all Collections:

image

Usage Examples

Let’s look at several examples of Postman API calls:

  • Getting Collection Information

In the previous rate limit image, we accessed the interface to get all Collections under the current account, with a response like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
    "collections": [
        {
            "id": "7ea4592c-848a-4a76-a4e4-5b1b0d0594f7",
            "name": "PostmanAPI",
            "owner": "4793508",
            "uid": "4793508-7ea4592c-848a-4a76-a4e4-5b1b0d0594f7"
        },
        {
            "id": "d6c64129-8c6c-48ec-968c-7f01a70a601b",
            "name": "Postman Echo",
            "owner": "4793508",
            "uid": "4793508-d6c64129-8c6c-48ec-968c-7f01a70a601b"
        },
        {
            "id": "f2777cee-5d92-4a0d-896e-e00ad27ef5bd",
            "name": "GitHub",
            "owner": "4793508",
            "uid": "4793508-f2777cee-5d92-4a0d-896e-e00ad27ef5bd"
        }
    ]
}

By providing the ID of the relevant interface, we can get detailed information about a single Collection using the interface:

1
https://api.getpostman.com/collections/{{collectionID}}

For example, here we can use Postman’s Pre-Script to first get the ID of a Collection with a specific name like PostmanAPI, then assign the ID to the environment variable {{collectionID}}. The code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
pm.sendRequest('https://api.getpostman.com/collections?apikey='+pm.environment.get("postman_api_key"), function (err, res) {
    if (err) {
        console.log(err);
    } else {
        var collections = res.json().collections
        for(let i=0;i<collections.length;i++){
            if(collections[i].name == "PostmanAPI"){
                pm.environment.set("collectionID", collections[i].id);
            }
        }
    }
});

As shown: image

  • Getting Environment Information

Similarly, we can get information about a single environment:

Pre-Script code as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
pm.sendRequest('https://api.getpostman.com/environments?apikey='+pm.environment.get("postman_api_key"), function (err, res) {
    if (err) {
        console.log(err);
    } else {
        var environments = res.json().environments
        for(let i=0;i<environments.length;i++){
            if(environments[i].name == "PostAPI"){
                pm.environment.set("envID", environments[i].id);
            }
        }
    }
});

Screenshot of the call:

image

  • Running a Specified Monitor

We can also immediately execute a specified Monitor through the interface. The interface returns execution results as shown:

image

Besides the examples above, detailed interface documentation for the Postman API can be found in the official API documentation. Similarly, the current interface call limit for free accounts is also 1,000 times.

Conclusion

Above is the introduction to the advanced features provided by Postman Cloud. As we can see, through Postman Cloud, we can leverage cloud service resources to accomplish some value-added functions that are not easily implemented by the local app, making it more convenient for team sharing and collaboration, enhancing convenience while accelerating our interface development or testing progress. Postman’s free version fully supports these value-added services but has certain usage limits. These value-added services can actually also be implemented through some open-source tools, which we can share with you in the future.

This concludes the systematic introduction to the Postman tool series. Welcome to continue discussing testing technology and sharing industry dynamics in the readers’ circle or by joining the WeChat group to grow together!


Built with Hugo
Theme Stack designed by Jimmy