Varibles
we have two types of varibles: Local Varibles and global varibles, while Api testing.
Local Varibles
Every rest project case can bind a group of varibles. All the varibles in the group can be used and updated at request building, response validation or Pure script.
-
While visually request building, we can use
{{varible-name}}
in any place like : URL, Header, or Body. it will automaticly be replaced to the target varible value at run time. -
In programming script block, like
Pre-Request
Script,Response Validation
Script andPure Script
, we can also access or update these varibles through a programing interface.
Different programming languag may have diffent interfaces, please check the examples there.
Bind a project case to a group of varibles by click the “vars” button under the case.
we can also add/delet/modfy these varible definitions in the varible editor.
- Varibles Access in Golang programing
Here is how the GetVars/SetVars is defined for RestBirdCtx. So you can use ctx.GetVars(key)
/ctx.SetVars(key, value)
to access the varibles.
func (ctx *RestBirdCtx) GetVars(key string) string {
return ctx.Vars[key]
}
func (ctx *RestBirdCtx) SetVars(key string, value string) {
ctx.Vars[key] = value
}
Besides, access the varibles in the ctx. We can also pull out all the varibles in a through callapi.GetEnvs(env)
to get the whole map of varibles.
- Varibles Access in Python programing
All the Varibles are stored in ctx.vars
dictionary. We can directly access it through ctx.vars[key]
Global Varibles
sometimes we would like to share something between a runing rest project and a runing tasks, we can use following method to access the global shared varibles
- Varibles Access in Golang programing
To Access the golobal varibles :
callapi.SetGlobal(key, value)
error, value = callapi.GetGlobal(key)
BTW, don’t forget to import callapi
package.
- Varibles Access in Golang programing
To Access the golobal varibles through ctx :
ctx.SetGlobal(key, value)
value = ctx.GetGlobal(key)