Skip to main content

Pre-request & Tests scripting

Every request has Pre-request and Tests script tabs. Pre-request scripts run before Nidra sends the request; Tests scripts run after the response arrives. Scripting is available on the Free tier.

Script APIs​

nidra.request​

In a Pre-request script, use nidra.request to read or change the outgoing request's headers, query parameters, path variables, and body. Headers, query parameters, and path variables also support direct property assignment.

nidra.request.headers.Authorization = `Bearer ${nidra.environment.get('token')}`;
nidra.request.query.page = '1';
nidra.request.path.userId = nidra.environment.get('userId');
nidra.request.body = JSON.stringify({ active: true });

Changes are applied before authentication, environment values, and the request are resolved for sending.

nidra.response​

Tests scripts can inspect the received response through nidra.response:

if (nidra.response.status !== 200) {
throw new Error(`Expected 200, received ${nidra.response.status}`);
}

const contentType = nidra.response.headers['content-type'];
const data = JSON.parse(nidra.response.body);

The response API exposes the status, headers, and body.

nidra.environment​

Read and update variables in the selected environment with get and set:

const token = nidra.environment.get('token');
nidra.environment.set('lastUserId', '42');

nidra.crypto​

Use the built-in helpers for common encodings and signatures:

const signature = nidra.crypto.hmacSha256('secret', 'message');
const digest = nidra.crypto.sha256('message');
const legacyDigest = nidra.crypto.md5('message');
const encoded = nidra.crypto.base64('message');

Available helpers are hmacSha256, sha256, md5, and base64.

Sandbox and v1 limitations​

Scripts run in a QuickJS-emscripten WebAssembly sandbox with zero ambient access. They cannot access your filesystem, operating system, network, or application internals, which makes synced scripts safe to auto-run.

Execution is synchronous in v1. Async functions, promises that require an event loop, and network calls such as fetch are not supported.