Learn to use global parameters and directory parameters in apipost in one minute

Time:2021-11-30

Global and catalog parameters

In the previous example, we filled in different request header, query and body parameters in a single interface. However, in actual projects, a batch of interfaces often have the same request parameters. At this point, we can use global parameters or directory parameters.

For example, for common token parameters, if we request any interface under the project to carry a token parameter in the header, of course we can write a token for the header parameter of each interface, but this is not conducive to later maintenance and modification.

Global parameters

Learn to use global parameters and directory parameters in apipost in one minute

We open the global parameter manager and fill in the token parameter in the global header:

Learn to use global parameters and directory parameters in apipost in one minute

Then each time we send the interface, we will automatically bring this parameter in the request header:

Learn to use global parameters and directory parameters in apipost in one minute

The usage of global query and global body is similar to that of global header and will not be repeated.

Directory parameters

The function of the directory parameter is the same as that of the global parameter, but the scope is different. The interface under directory B will not use the directory parameter of directory a of the same level as the sending parameter.

We can passEdit directoryFill in the catalog parameters:

Learn to use global parameters and directory parameters in apipost in one minute

Then every time we send the interface under this directory, we will automatically bring this parameter in the request header:

Learn to use global parameters and directory parameters in apipost in one minute

Priority of parameter

When the same parameter is used in global parameter, directory parameter and interface, the parameter value will be read according to the following priority:

Single interface > catalog parameters > global parameters

As in the above example, if the header parameter token is defined in the global parameter, directory parameter and interface:

Global parameter: token value: 698d51a19d8a121ce581499d7b701668 / / lowest priority
Directory parameter: token value: b50e345cc9febd86dedec551ebcc505 / / second priority
Single interface parameter: token value: a1a9db893bb8a28ccb665d2af54d9417 / / highest priority

Then the final sent token value is a1a9db893bb8a28ccb665d2af54d9417