Available Objects
In pre-request scripts, you have access to:bru- Main Bruno API objectreq- Request objecttest- Test function (can run tests in pre-request scripts)expect/assert- Chai assertion librariesconsole- Logging functions
The
res (response) object is not available in pre-request scripts since the request hasn’t been sent yet.Request Object (req)
Thereq object represents the outgoing HTTP request.
Properties
The request URL
HTTP method (GET, POST, PUT, DELETE, etc.)
Request headers as key-value pairs
Request body (automatically parsed if JSON)
Request timeout in milliseconds
Name of the request
Path parameters array
Tags associated with the request
Methods
URL Methods
Returns the full request URL
Sets the request URLParameters:
url(string) - The new URL
Returns the host from the URL (including port)
Returns the path portion of the URL (with path params interpolated)
Returns the query string without the leading
?Header Methods
Gets a specific header valueParameters:
name(string) - Header name
Sets a header valueParameters:
name(string) - Header namevalue(string) - Header value
Removes a headerParameters:
name(string) - Header name
Returns all headers as an object
Replaces all headersParameters:
headers(object) - New headers object
Removes multiple headersParameters:
names(array) - Array of header names
Body Methods
Gets the request bodyParameters:
options.raw(boolean) - If true, returns raw string instead of parsed JSON
Sets the request bodyParameters:
data(any) - Body data (object will be stringified if JSON content type)options.raw(boolean) - If true, sets raw data without JSON processing
Other Methods
Returns the HTTP method
Sets the HTTP methodParameters:
method(string) - HTTP method (GET, POST, etc.)
Returns the request timeout in milliseconds
Sets the request timeoutParameters:
timeout(number) - Timeout in milliseconds
Sets the maximum number of redirects to followParameters:
max(number) - Maximum redirects
Returns the authentication mode in useReturns:
'none', 'basic', 'bearer', 'oauth2', 'awsv4', 'digest', or 'wsse'Returns the request name
Returns array of path parameters
Returns array of request tags
Returns the execution mode (e.g., ‘cli’, ‘gui’)
Registers a callback to run if the request failsParameters:
callback(function) - Function to call on failure
Disables automatic JSON parsing of the response body
Bruno Object (bru)
Thebru object provides methods for managing variables, environment, and request flow. See the Post-response Scripts page for complete bru API reference, as all methods are available in both contexts.
Key methods commonly used in pre-request scripts:
Common Patterns
Authentication
Dynamic Request Body
Conditional Logic
URL Manipulation
Next Steps
Post-response Scripts
Process responses and extract data
Test API
Write test assertions