Pre-request & Test Scripts (vx API)
Run JavaScript before and after every request with the vx API — assertions, variable manipulation, and Postman-compatible script conversion.
Two scripts per request
- Pre-request script — runs before the request is sent. Use it to compute signatures, set headers, or seed variables.
- Test script — runs after the response. Use it for assertions and to chain dependent requests.
The vx object
| Call | What it does |
|---|---|
vx.response.json() | Parse the response body as JSON. |
vx.response.to.have.status(200) | Chai-style status assertion. |
vx.clusterVariables.set(key, value) | Save a value into the cluster's variable store. |
vx.clusterVariables.get(key) | Read a previously-saved variable. |
vx.test(name, fn) | Define a named test that shows pass/fail in the response panel. |
vx.expect(value) | Chai-style expect assertion (.to.equal, .to.be.greaterThan, etc.). |
Example: extract a token and chain
// Pre-request: nothing
// Test:
const data = vx.response.json();
vx.test('login succeeds', () => {
vx.response.to.have.status(200);
vx.expect(data.token).to.be.a('string');
});
vx.clusterVariables.set('token', data.token);
Postman compatibility
Imported Postman collections work out of the box: pm.environment → vx.clusterVariables, pm.response → vx.response, pm.test → vx.test, pm.expect → vx.expect. Conversion is automatic and reversible.
Editor UX
- Full JS tokenizer-based syntax highlight: keywords, API objects (
vx,pm,console,JSON,Math,Date), strings, comments, numbers, arrow functions. - Gutter line numbers with synced scrolling between the textarea and highlight layer.
- Tab inserts spaces (no focus loss).
console.log()output streams into the script panel.
Sandbox note: Scripts execute in a renderer-level sandbox with access to the cluster's variables, the request, the response, and a small standard-library surface — no Node APIs.