Skip to content
Vegha Docs

Scripting Overview

Scripting lets you run small pieces of JavaScript around a request — to prepare data before it is sent and to process the response after it arrives.

Common uses include:

  • Setting or computing variables before a request runs.
  • Calculating signatures, timestamps, or other dynamic values.
  • Extracting values from a response to chain into the next request.
  • Asserting on responses with tests.

Scripts run in a sandboxed JavaScript engine (Jint). The sandbox is deliberately restrictive so that running a collection cannot harm your machine:

  • No filesystem access — scripts cannot read or write files.
  • No process access — scripts cannot spawn processes or read the environment.
  • Hard limits on memory, execution time, and recursion depth — a runaway script is stopped automatically.

There are two kinds of script:

TypeRunsTypical use
Pre-requestBefore the request is sentSet variables, mutate headers, compute values
Post-responseAfter the response is receivedRead the response, extract values, branch logic

Scripts can be attached at three levels, each with its own tab:

  • Request — runs for that single request.
  • Folder — runs for every request in the folder.
  • Collection — runs for every request in the collection.

This lets you put shared setup (for example refreshing a token) on the collection and keep request-specific logic local.

Scripts interact with the run through three objects:

ObjectAvailable inPurpose
bruBothRead and write variables and the environment
reqBothInspect and mutate the outgoing request
resPost-response onlyRead the response

A test() / expect() API is also available for writing assertions.

See the Scripting API reference for the full list of members.