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.
What scripting is for
Section titled “What scripting is for”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.
The Jint sandbox
Section titled “The Jint sandbox”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.
Pre-request vs post-response
Section titled “Pre-request vs post-response”There are two kinds of script:
| Type | Runs | Typical use |
|---|---|---|
| Pre-request | Before the request is sent | Set variables, mutate headers, compute values |
| Post-response | After the response is received | Read the response, extract values, branch logic |
Where scripts live
Section titled “Where scripts live”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.
The scripting objects at a glance
Section titled “The scripting objects at a glance”Scripts interact with the run through three objects:
| Object | Available in | Purpose |
|---|---|---|
bru | Both | Read and write variables and the environment |
req | Both | Inspect and mutate the outgoing request |
res | Post-response only | Read the response |
A test() / expect() API is also available for writing assertions.
See the Scripting API reference for the full list of members.