First knowledge of Postman

Source: Internet
Author: User
Tags json send cookies postman interceptor
the old analog request method

In the process of developing the app interface, after the general interface has been written, the backend development will simulate the call request. Before using postman, I would basically use a browser to simulate a general GET request. And for post requests, I'm generally used to writing code to invoke. Can be simulated in Java, of course, Python will be more concise. Let's look at some of the drawbacks of this approach. It is not easy to manage requests, usually using a write one, if you want to use it later, you can only rely on the browser's history. For the development, testing, production environment, the requested domain name parameters may be different, which for the maintenance of our request has brought great difficulties. The returned results obtained by the browser or by themselves are unformatted text and need to be bejson to improve the readability of the data with postman mock requests

Today, however, it is necessary to recommend a sharp weapon for a mock request--postman to see how it gracefully solves these three problems. manage requests with collections

In postman, the request can be saved, and it is similar to a file. and collection similar folder, you can put the same project request in a collection easy to manage and share, collection inside can also build folders.

Environment Variables

For example, we request the domain name, development, testing, production environment must be different. Some request parameters, such as the user ID of the test environment and the user ID of the online environment, must be different. This is similar to what we do in Maven by configuring the profile to play different environments in the release package. Of course, Postman also provides globals, the so-called global variables, that are not related to the environment.

Request result Formatting

just a little more praise.

Postman is powerful and convenient for mock requests, here are a few more words:
can simulate various HTTP methods, Post, Get, Put, delete, etc.
A variety of headers can be added, but some headers are blocked by the chrome and XMLHttpRequest specifications, as follows: Accept-charset accept-encoding access-control-request-headers Access-control-request-method Connection Content-length Cookie Cookie 2 content-transfer-encoding Date Expect Host keep-alive Origin Referer TE Trailer transfer-en Coding Upgrade User-agent Via

The good news is that, starting with the Postman v0.9.6 version, we can use interceptors to send these restricted headers, which is the need to install the Postman Interceptor Plugin

Install Postman Interceptor not only can send cookies, but also can use browser cookies. That way, if we just landed in Chrome, we could get a variety of request results that could only be accessed after landing. This is definitely a practical function.

There is a benefit to installing the Postman Interceptor. That is the request to intercept chrome, which can be crawled into postman automatically via Chrome's request. Just turn on the Postman Interceptor blocking feature in Chrome and configure the interception rules, which by default intercept all requests, and you can intercept specific requests according to your own rules. With it it's the equivalent of replacing us to record requests, and then we can do something ... What else can postman do?

Postman In addition to being a great simulation request tool, it also contains a very powerful interface test function:

The test consists of three parts, the pre-request that ran before the request was initiated, the test that ran after the response was received, and the collection Runner that ran all the requests at once Pre-request

Pre-request and test language are JavaScript, the common function can be implemented by the Code snippets on the right, click can be inserted into the area.
You can see the functions commonly used in pre-request, both the setting of environment variables and the setting of global variables. Clear Test

The snippets of test is much richer than pre-request, such as checking the status code, checking the response string, validating the JSON, checking the header, and limiting the response time.
If you need to save the data that the server responds to, it needs to be done in a later request. Collection Runner

After writing a lot of tests, you can use collection runner to run the entire collection, and the entry is in the runner of the top row of the main interface. Select collection, environment, and optionally load JSON and CSV as the data source if necessary. Click Start Test Run to see the results. write it in the back .

This article simply introduces some of the advantages of postman, I just as a experience to my own feel good place to recommend to everyone, of course postman may have a lot of powerful features I did not use. In the following article I will share a practical example of how I can automate the testing of all the interfaces of a recently developed functional module with postman.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.