How does postman do interface association

Table of contents

1. Extract data

2. Verification

 3. Put in the data

4. Verify


In postman, when one of our interfaces needs to return data from another interface, we need to do interface association at this time.

I will teach step by step how to operate

First of all, I have two interfaces in postman. Due to time reasons, these two interfaces have nothing to do with the actual business. Just for teaching, I will force the connection here.

 ok, the interface is available, we know that the steps associated with the interface are to extract data --- verify --- put data --- execute  Now that the interface is available, let's extract the data first.

1. Extract data

        We first select the interface we need to extract data, click tests, and enter the code in it:

        var jsonData = JSON.parse(responseBody);

        pm.globals.set("dizhi",jsonData.aa);

Let me briefly talk about the function of each line of code here. The first line is to explain to postman that what we extract is the data in the returned body.

The pm.globals.set() in the second line of code is to set the data in the set brackets as a global variable, among them, pm.globals.set("dizhi",jsonData.aa); the data in the brackets "dizhi" It is the variable name we use to store data. It can be set here as long as it meets the variable name setting requirements of the code. jsondata in "jsonData.aa" represents all the data returned to the body, and .aa after jsondaya is equivalent to returning The aa value of the json data, let me use the data to explain it here, assuming that the data returned by an interface is {" aa ":123,"bb":456}, if we want to extract the data of 123, we only need Need to fill in var jsonData = JSON.parse(responseBody);pm.globals.set("dizhi", jsonData.aa ); among them, our variable, "dizhi" will represent data 123, if we encounter What about the complicated return data? Suppose we need to extract user data from {" aa ":{" name ":{ user :admin,password:12345}}}. Here are our settings var jsonData = JSON.parse(responseBody);pm.globals.set("dizhi", jsonData.aa.name.user );, here we can parse layer by layer. There is a lot of nonsense, here we start the next step

2. Verification

After we fill in the data for the interface to be extracted, we click Execute. After the execution, we click the eye sign in the upper right corner of the interface. Here we can see that the variable name "dizhi" set by our lock already has a value "Changsha "Yes.

 3. Put in the data

We open the interface that needs the data of Changsha, put the variable into the position we need, suppose we need to put data into the parameter ticy, we put the variable { {dizhi}} in the value of the parameter, and use 2 braces Just enclose it.

4. Verify

We click to execute "the interface to extract data", after clicking execute, we hover the mouse over the view in the upper left corner, and then click show postman in the expanded list data. . We can see our request data, and then see if the data extraction is successful.

 Check if the data has been substituted into

 Here we see that the city already has the value of Changsha, and it has been uploaded.

Today's sharing has been completed, thank you for your support.

Guess you like

Origin blog.csdn.net/m0_58002043/article/details/126497886