Used to set the prerequest for the postman API
You can configure multiple rules for the prerequest
prerequest configurationpostman.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());
});
```
prerequest to APIs with specific annotationspostman.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());
});
```
prerequest to APIs without specific annotationspostman.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 in the configuration, selecting which one to use with code commentspostman.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"))
Usage:
/**
* Get the user list
*
* @param type User 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));
}
Set prerequest on the folder using pre-request scripts.
Multiple rules can be set.
The context is class.
Set prerequest on the collection using pre-request scripts.
Multiple rules can be set.
Note that collection.postman.prerequest has no context, meaning it is null.