Clone
3
Scripts
Pavel Baksy edited this page 2026-05-18 17:37:35 +02:00
Table of Contents
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
- Preprocessing script
- Variable substitution (
{{variable_name}}) - HTTP request
- Postprocessing script
- 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.