Scripts
Scripts let you attach JavaScript snippets to individual HTTP requests. They run in a sandboxed context with access to the request and response data.
Script Types
Section titled “Script Types”Pre-request Script
Section titled “Pre-request Script”Runs before the request is sent. Use it to:
- Log request details with
console.log() - Modify request properties programmatically
- Prepare dynamic data
Available API:
| Variable | Type | Description |
|---|---|---|
console | object | console.log(), console.warn(), console.error(), console.info() for debugging |
request.method | string | HTTP method (GET, POST, etc.) |
request.url | string | The request URL |
request.headers | object | Key-value map of request headers |
request.params | object | Key-value map of query parameters |
request.body | string | Raw request body |
// Pre-request script exampleconsole.log('Sending', request.method, 'to', request.url)console.log('Headers:', JSON.stringify(request.headers))Post-response Script
Section titled “Post-response Script”Runs after the response is received. All pre-request variables are available, plus:
| Variable | Type | Description |
|---|---|---|
response.statusCode | number | HTTP status code (e.g. 200) |
response.statusText | string | Status text (e.g. “OK”) |
response.headers | object | Key-value map of response headers |
response.body | string | Raw response body |
response.contentType | string | Content-Type header value |
// Post-response script exampleconsole.log('Status:', response.statusCode, response.statusText)console.log('Response body:', response.body)
if (response.statusCode === 200) { console.log('Request succeeded!')} else { console.warn('Request failed with status', response.statusCode)}Using Scripts
Section titled “Using Scripts”- Open a request
- Click the Scripts tab
- Write JavaScript in the Pre-request Script or Post-response Script textarea
- Send the request — scripts execute automatically
Script Logs
Section titled “Script Logs”Script output from console.log/warn/error/info appears in the script logs panel below the editors. Each entry includes:
- Log type (log, warn, error, info)
- Timestamp
- Message content
Example: Full Workflow
Section titled “Example: Full Workflow”// Pre-request: Log the requestconsole.log('Starting request to', request.url)
// Post-response: Validate the responseif (response.statusCode >= 400) { console.error('Error:', response.statusCode, response.body)} else { console.log('Success:', response.statusCode) const data = JSON.parse(response.body) console.log('Items count:', data.length)}