Use variables in required scripts #103
-
Hi. Is it possible to access the available variables within required scripts? My current goal is to define some default headers for all request in a file. Some of the header values come from the environment, some others from imported variables. I can achieve that with the E.g. my minimal test example is this: Request:
Script: module.exports = {
setHeaders: (request) => {
request.headers["SomeHeader"] = some_value;
request.headers["SomeOtherHeader"] = some_other_value;
},
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The easiest thing to do is to pass you the variables as objects. Either just use
If you require the script in several places, you can have a look at the hook api. That's exactly what it's for and it has easier access to the variables and interface. With this I extend httpyac with the companies internal api |
Beta Was this translation helpful? Give feedback.
The easiest thing to do is to pass you the variables as objects. Either just use
this
or in my eyes better, use the variables explicitly.If you require the script in several places, you can have a look at the hook api. That's exactly what it's for and it has easier access to the variables and interface. With this I extend httpyac with the companies internal api