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
string
The request URL
string
HTTP method (GET, POST, PUT, DELETE, etc.)
object
Request headers as key-value pairs
any
Request body (automatically parsed if JSON)
number
Request timeout in milliseconds
string
Name of the request
array
Path parameters array
array
Tags associated with the request
Methods
URL Methods
function
Returns the full request URL
function
Sets the request URLParameters:
url(string) - The new URL
function
Returns the host from the URL (including port)
function
Returns the path portion of the URL (with path params interpolated)
function
Returns the query string without the leading
?Header Methods
function
Gets a specific header valueParameters:
name(string) - Header name
function
Sets a header valueParameters:
name(string) - Header namevalue(string) - Header value
function
Removes a headerParameters:
name(string) - Header name
function
Returns all headers as an object
function
Replaces all headersParameters:
headers(object) - New headers object
function
Removes multiple headersParameters:
names(array) - Array of header names
Body Methods
function
Gets the request bodyParameters:
options.raw(boolean) - If true, returns raw string instead of parsed JSON
function
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
function
Returns the HTTP method
function
Sets the HTTP methodParameters:
method(string) - HTTP method (GET, POST, etc.)
function
Returns the request timeout in milliseconds
function
Sets the request timeoutParameters:
timeout(number) - Timeout in milliseconds
function
Sets the maximum number of redirects to followParameters:
max(number) - Maximum redirects
function
Returns the authentication mode in useReturns:
'none', 'basic', 'bearer', 'oauth2', 'awsv4', 'digest', or 'wsse'function
Returns the request name
function
Returns array of path parameters
function
Returns array of request tags
function
Returns the execution mode (e.g., ‘cli’, ‘gui’)
function
Registers a callback to run if the request failsParameters:
callback(function) - Function to call on failure
function
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