docs RestermScript
Modules and exports
Share logic between request files with .rts modules and @use.
Modules are .rts files that you import with @use.
module <name>declares the module name (required when importing withoutas, and it must be the first statement).exportexposes a name from a module.@use ./path.rtsor@use ./path.rts as aliasimports a module into its request, or into the whole file when it comes before the first###line.- If you omit
as, the module name becomes the alias. - Modules are cached, so top-level mutable state can persist across runs.
Example:
# helpers.rts
module helpers
export fn authHeader(token) {
return token ? "Bearer " + token : ""
}# @use ./rts/helpers.rts
Authorization: {{= helpers.authHeader(vars.get("auth.token")) }}Modules have access to rts and, when the host provides it, request. A module cannot declare these names or stdlib, but it can declare any other name, including a standard library name such as json. Pass other host objects (env, vars, last, response, trace, stream, or a test block's t) as function arguments. These objects expire when the block or expression passing them returns. stdlib is a deprecated alias for rts.