设置
postman
API的prerequest
允许设置多条规则
prerequest
配置示例如下postman.prerequest=```
pm.environment.get("variable_key");
pm.globals.get("variable_key");
pm.variables.get("variable_key");
pm.environment.set("variable_key", "variable_value");
pm.globals.set("variable_key", "variable_value");
pm.environment.unset("variable_key");
pm.globals.unset("variable_key");
pm.sendRequest("https://postman-echo.com/get", function (err, response) {
console.log(response.json());
});
```
api
加上prerequest
postman.prerequest[@com.itangcent.common.annotation.RequiredLogin]=```
pm.environment.get("variable_key");
pm.globals.get("variable_key");
pm.variables.get("variable_key");
pm.environment.set("variable_key", "variable_value");
pm.globals.set("variable_key", "variable_value");
pm.environment.unset("variable_key");
pm.globals.unset("variable_key");
pm.sendRequest("https://postman-echo.com/get", function (err, response) {
console.log(response.json());
});
```
api
加上prerequest
postman.prerequest[!@com.itangcent.common.annotation.Public]=```
pm.environment.get("variable_key");
pm.globals.get("variable_key");
pm.variables.get("variable_key");
pm.environment.set("variable_key", "variable_value");
pm.globals.set("variable_key", "variable_value");
pm.environment.unset("variable_key");
pm.globals.unset("variable_key");
pm.sendRequest("https://postman-echo.com/get", function (err, response) {
console.log(response.json());
});
```
prerequest
,由代码注释来选择使用哪个postman.prerequest.groupA=```
pm.environment.get("variable_key");
```
postman.prerequest.groupB=```
pm.globals.get("variable_key");
```
postman.prerequest.groupC=```
pm.environment.set("variable_key", "variable_value");
```
postman.prerequest.groupD=```
pm.globals.set("variable_key", "variable_value");
```
postman.prerequest[#prerequest]=groovy:config.get("postman.prerequest."+it.doc("prerequest"))
使用如下:
/**
* 获取用户列表
*
* @param type 用户类型 {@link com.itangcent.common.constant.UserType}
* @prerequest groupA
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public IResult list(Integer type) {
...
return Result.success(Collections.singletonList(userInfo));
}
设置folder
上的prerequest
允许设置多条规则
上下文为class
设置collection
上的prerequest
允许设置多条规则
注意collection.postman.prerequest
无上下文,即it
为null