3
Scripts
Pavel Baksy edited this page 2026-05-18 17:37:35 +02:00

Scripts

Roster supports JavaScript preprocessing and postprocessing scripts via GJS (GNOME JavaScript).

Preprocessing — runs before the request is sent; can modify request. Postprocessing — runs after the response; can read response and set variables.

Open the Scripts tab in the request editor. Save with Ctrl+S.

Preprocessing API

request.method    // "GET", "POST", "PUT", "DELETE"
request.url       // Full URL string
request.headers   // Header key-value object
request.body      // Request body string

roster.getVariable(name)
roster.setVariable(name, value)
roster.setVariables({key: value})
roster.project.name
roster.project.environments  // string[]

console.log(...) / console.error(...)

Example:

const token = roster.getVariable('auth_token');
request.headers['Authorization'] = 'Bearer ' + token;
request.headers['X-Request-Time'] = new Date().toISOString();

Postprocessing API

response.body         // string, read-only
response.headers      // object, read-only
response.statusCode   // number
response.statusText   // string
response.responseTime // number (ms)

roster.setVariable(name, value)
roster.setVariables({key: value})
// roster.getVariable() is NOT available here

console.log(...) / console.error(...)

Example:

const data = JSON.parse(response.body);
roster.setVariables({
    access_token: data.access_token,
    user_id: data.user_id
});

Execution Order

  1. Preprocessing script
  2. Variable substitution ({{variable_name}})
  3. HTTP request
  4. Postprocessing script
  5. Response displayed and saved to history

Limitations

  • Synchronous only — no async/await, setTimeout, fetch
  • No file system, shell, or external library access

Error Handling

Script errors are shown in the output panel; the request still executes.

try {
    const data = JSON.parse(response.body);
    roster.setVariable('user_id', data.user.id);
} catch (e) {
    console.error('Parse error:', e.message);
}

See API-Reference for the full API reference.