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)
URL Methods
URL Methods
Header Methods
Header Methods
Body Methods
Body Methods
Other Methods
Other Methods
Response Object (res)
Status Methods
Status Methods
Header Methods
Header Methods
Body Methods
Body Methods
Direct Access
Direct Access
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
Advanced Patterns
Chaining Requests
Error Handling
Custom Utilities
Scripts run in a sandboxed environment. Use Developer Mode for full Node.js access.
Best Practices
Keep Scripts Focused
Keep Scripts Focused
Each script should have a single, clear purpose. Separate setup, execution, and validation logic.
Use Descriptive Test Names
Use Descriptive Test Names
Handle Async Operations Properly
Handle Async Operations Properly
Always use
await with async operations and wrap tests with await test():Clean Up Resources
Clean Up Resources
Clear sensitive data and temporary variables after use:
Related Resources
Variables
Learn about variable scopes and management
Assertions
Master test assertions and operators
Workflows
Build complex multi-request workflows
Environments
Manage environment variables