Skip to main content
Bruno provides a powerful JavaScript scripting engine that allows you to automate complex workflows, manipulate requests and responses, and integrate with external libraries. Scripts can be executed at different stages of the request lifecycle.

Script Types

Bruno supports three types of scripts:

Pre-Request

Execute before sending the request

Post-Response

Execute after receiving the response

Tests

Run assertions and validations

Pre-Request Scripts

Pre-request scripts run before Bruno sends the HTTP request. Use them to set headers, modify the request body, generate dynamic values, or perform authentication.

Basic Example

Authentication Example

Dynamic Request Body

Post-Response Scripts

Post-response scripts execute after receiving the response. Use them to extract data, set variables for subsequent requests, or perform custom processing.

Extract Response Data

Response Transformation

Test Scripts

Test scripts allow you to write assertions and validations using Chai assertion library.

Basic Tests

Advanced Assertions

Request and Response API

Request Object (req)

Response Object (res)

Built-in Libraries

Bruno includes several libraries for common tasks:

crypto-js

Encryption and hashing

axios

HTTP client for making requests

uuid

Generate unique identifiers

cheerio

Parse and query HTML

jsonwebtoken

Work with JWT tokens

xml2js

Parse XML responses
All built-in libraries are available without installation. Just require() them in your scripts.

Advanced Patterns

Chaining Requests

Error Handling

Custom Utilities

Scripts run in a sandboxed environment. Use Developer Mode for full Node.js access.

Best Practices

Each script should have a single, clear purpose. Separate setup, execution, and validation logic.
Always use await with async operations and wrap tests with await test():
Clear sensitive data and temporary variables after use:

Variables

Learn about variable scopes and management

Assertions

Master test assertions and operators

Workflows

Build complex multi-request workflows

Environments

Manage environment variables