This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together

In daily development, we often need to deal with the interface, and get the interface must be tested in advance, so it is very necessary to have a more powerful Http request simulation tool, now popular this tool is also quite many, here is mainly introduced Postman.

First, Postman instructions

Postman is a Chrome extension that provides powerful Web API & HTTP request debugging. It can send any type of HTTP request (GET, HEAD, POST, PUT…). , with any number of arguments + headers.

Supports different authentication mechanisms (BASIC, Digest, OAuth) and syntax highlighting of received responses (HTML, JSON or XML). Postman is able to preserve historical requests so that we can easily re-send requests, and has a “collection” feature for storing all requests in the same API/ domain.

1. Basic functions

First of all, let’s take a look at the basic functions of Postman, which I’m not going to go into

2. Advanced functions

In the process of development, the interface is debugged and saved in Postman. However, if you debug the test Environment, it is more troublesome to access the interface of the test Environment. You need to rewrite the interface, parameters, tokens and so on, which wastes time. To solve this problem, switch the Environment to quickly access the development Environment and test Environment. Here is how to do it.

The version used this time is V8.6.2, the interface is different to update

2.1 create the Environment

Create an environment named Mango-dev with url and token parameters

2.2 Testing whether Parameter Configuration is successful

Create a request, switch the environment in the upper right corner, enter the interface address, note that {{URL}} is the way to reference our parameters, click Send, prove that my parameter Settings are effective

2.3 Updating Environment Information

According to the above Settings, the URL is not required and the token can be configured according to the URL. However, each time the token is invalid, a login interface needs to be invoked and the obtained login information is put into the environment variable. But I’m lazy. Can I access the login interface and automatically place authentication information on the environment variable? The answer is yes, read on (▽)

First write a good login interface, choose a good environment, my login after the verification information

Click Tests and type the following statement. The token will be assigned to the environment when the login is performed

var res =  JSON.parse(responseBody);
pm.environment.set("token",res.data.token);
Copy the code

2.4 Using environment Information

Select the environment, create the business interface (mine is menu management), select Authorization, and select API Key in Type (select according to the need to log in to the system) as follows

2.5 Unified Settings

Now there is another trouble. If the interface is not copied, every time I create an interface, I need to click the Authorization to set Token as above. Is there a way that THE key has been set for the interface I create, so I only need to fill in the URL and parameter information? The answer is yes.

In Postman, every interface has a folder. We can work on files, as shown below, mango is my folder

Click the Mango folder, and the Authorization menu familiar to us will be displayed on the right side. Refer to the previous step to configure token information and save it

Right-click the interface folder, click the menu New Request, click the Authorization of the New Request, and find the default first inherit Auth from parent, so that the token does not need to configure, but the configuration information of the folder is used.

Check that the data is not checked. Perfect work