Bruno Commands
Bruno is a lightweight, open-source, Git-native API client designed for testing and developing APIs. Unlike Postman, Bruno stores your collections as plain-text files (.bru format) that can be versioned with Git, making it ideal for team collaboration and CI/CD pipelines.
Installation
| Platform | Command |
|---|---|
| macOS (Homebrew) | brew install bruno |
| Linux (Snap) | snap install bruno |
| Linux (APT) | sudo apt-get install bruno |
| Windows (Chocolatey) | choco install bruno |
| npm | npm install -g @usebruno/cli |
| Download | Visit usebruno.com/downloads |
Getting Started
Launch Bruno GUI
bruno
Create a New Collection
bruno create-collection my-api-collection
Open Existing Collection
bruno /path/to/collection
Collection Management
Collection Structure
Bruno stores collections as directories with .bru files:
my-api-collection/
├── bruno.json # Collection metadata
├── environments/
│ ├── Development.json
│ └── Production.json
├── auth/
│ └── auth.bru
└── users/
├── get-all-users.bru
├── create-user.bru
└── update-user.bru
Import from Postman
# In Bruno GUI: Import → Select Postman collection JSON
# Or use CLI (if available for your Bruno version)
Organize Requests in Folders
Create folders within your collection to organize requests:
- Right-click in collection tree → New Folder
- Name folders logically (e.g., users, products, auth)
- Drag requests between folders
Export Collection
# Collections are stored as plain files (.bru format)
# Simply commit to Git or share the directory
Bru Language (Request Format)
Bruno uses .bru files—a simple, readable markup language for requests.
Basic Request File
meta {
name: Get All Users
type: http
seq: 1
}
get {
url: {{baseUrl}}/api/users
auth: bearer
}
params:query {
limit: 10
offset: 0
}
headers {
Content-Type: application/json
User-Agent: Bruno/v1
}
auth:bearer {
token: {{authToken}}
}
Request with Body
meta {
name: Create User
type: http
seq: 2
}
post {
url: {{baseUrl}}/api/users
}
headers {
Content-Type: application/json
}
body:json {
{
"name": "John Doe",
"email": "john@example.com",
"role": "admin"
}
}
Form Data Request
meta {
name: Upload Profile Picture
type: http
seq: 3
}
post {
url: {{baseUrl}}/api/users/{{userId}}/avatar
}
body:form-urlencoded {
username: johndoe
email: john@example.com
}
Form Multipart (File Upload)
meta {
name: Upload File
type: http
seq: 4
}
post {
url: {{baseUrl}}/api/files/upload
}
body:multipartForm {
file: @/path/to/file.pdf
description: My document
}
CLI Commands
Run Collection or Request
# Run entire collection
bru run /path/to/collection
# Run specific request
bru run /path/to/collection/requests/get-users.bru
# Run with specific environment
bru run /path/to/collection --env Production
# Run in JSON reporter format
bru run /path/to/collection --reporter json
# Run with HTML report
bru run /path/to/collection --reporter html --output report.html
Available Reporters
| Reporter | Command |
|---|---|
| CLI (default) | bru run collection --reporter cli |
| JSON | bru run collection --reporter json |
| HTML | bru run collection --reporter html --output report.html |
| JUnit | bru run collection --reporter junit |
Run with Variables
# Pass environment variables
bru run /path/to/collection --env Development
# Override specific variable
bru run /path/to/collection --env Production --variable apiKey=abc123
Fail on Error
# Exit with non-zero status if any test fails (useful for CI/CD)
bru run /path/to/collection --failOnError
Verbose Output
# Show detailed request/response information
bru run /path/to/collection --verbose
Environment Variables
Create Environment File
Environment files are stored as environments/EnvName.json:
{
"baseUrl": "https://api.example.com",
"apiKey": "your-api-key-here",
"authToken": "bearer-token",
"userId": "12345",
"timeout": 5000
}
Using Variables in Requests
get {
url: {{baseUrl}}/api/users/{{userId}}
timeout: {{timeout}}
}
headers {
Authorization: Bearer {{authToken}}
X-API-Key: {{apiKey}}
}
Switch Environments
# Via CLI
bru run /path/to/collection --env Development
# Via GUI: Select environment dropdown in Bruno interface
Environment Variables Types
| Type | Example | Usage |
|---|---|---|
| String | "apiKey": "abc123" | {{apiKey}} |
| Number | "timeout": 5000 | {{timeout}} |
| Boolean | "debug": true | {{debug}} |
| Object | "config": {...} | Access with scripting |
Secrets Management
# Create a .env file for sensitive data (add to .gitignore)
echo "PROD_API_KEY=secret123" > .env
# Use in environment file with reference
# Or use Bruno's GUI to mark fields as "Secret"
Pre-Request Scripts
Add JavaScript before the request is sent:
// Set dynamic values
bru.setEnvVar('timestamp', Date.now());
bru.setEnvVar('nonce', Math.random().toString(36).substring(7));
// Conditional logic
if (bru.getEnvVar('env') === 'production') {
bru.setEnvVar('timeout', 10000);
}
// Log debug info
console.log('Sending request to', bru.getEnvVar('baseUrl'));
Post-Response Scripts
Execute JavaScript after receiving the response:
// Access response data
const responseData = res.getBody();
const statusCode = res.getStatus();
const headers = res.getHeaders();
// Save values for next request
if (statusCode === 200) {
bru.setEnvVar('authToken', responseData.token);
bru.setEnvVar('userId', responseData.user.id);
}
// Log response
console.log('Status:', statusCode);
console.log('Response:', JSON.stringify(responseData, null, 2));
Common Response Operations
// Get status code
const status = res.getStatus();
// Get body as string
const body = res.getBody();
// Parse JSON body
const data = res.getBody(true); // true = parse as JSON
// Get headers
const contentType = res.getHeader('content-type');
// Get specific header
const authHeader = res.getHeader('authorization');
Assertions and Tests
Built-in Test Assertions
// Status code assertion
tests['Status is 200'] = (res.getStatus() === 200);
// Response body contains
tests['Response contains user'] = res.getBody().includes('john');
// JSON response validation
const data = res.getBody(true);
tests['User ID exists'] = data.user && data.user.id > 0;
// Response time
tests['Response time < 500ms'] = res.getResponseTime() < 500;
// Header validation
tests['Content-Type is JSON'] = res.getHeader('content-type').includes('application/json');
Complex Test Example
const data = res.getBody(true);
tests['Status is 201'] = res.getStatus() === 201;
tests['ID is a number'] = typeof data.id === 'number';
tests['Email is valid'] = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(data.email);
tests['Created at is ISO date'] = !isNaN(Date.parse(data.createdAt));
// Save for next request
if (tests['Status is 201']) {
bru.setEnvVar('newUserId', data.id);
}
Authentication
Bearer Token
auth:bearer {
token: {{authToken}}
}
Basic Auth
auth:basic {
username: {{username}}
password: {{password}}
}
API Key (Header)
headers {
X-API-Key: {{apiKey}}
Authorization: ApiKey {{apiKey}}
}
API Key (Query Parameter)
params:query {
api_key: {{apiKey}}
apiToken: {{token}}
}
OAuth 2.0
auth:oauth2 {
grant_type: authorization_code
authorization_url: https://provider.com/oauth/authorize
token_url: https://provider.com/oauth/token
client_id: {{clientId}}
client_secret: {{clientSecret}}
scope: read write
}
Digest Auth
auth:digest {
username: {{username}}
password: {{password}}
}
Request Types and Methods
GET Request
meta {
name: Fetch User
type: http
seq: 1
}
get {
url: {{baseUrl}}/api/users/{{userId}}
}
params:query {
includeProfile: true
fields: id,name,email
}
POST Request
post {
url: {{baseUrl}}/api/users
}
body:json {
{
"name": "Jane Doe",
"email": "jane@example.com"
}
}
PUT/PATCH Request
put {
url: {{baseUrl}}/api/users/{{userId}}
}
body:json {
{
"name": "Jane Smith",
"status": "active"
}
}
DELETE Request
delete {
url: {{baseUrl}}/api/users/{{userId}}
}
Request with Headers
headers {
Content-Type: application/json
Accept: application/json
User-Agent: Bruno/v1.0
X-Request-ID: {{requestId}}
Authorization: Bearer {{token}}
}
Advanced Features
Collection-Level Variables
Define variables in bruno.json:
{
"name": "My API Collection",
"version": "1.0",
"variables": {
"baseUrl": "https://api.example.com",
"version": "v1",
"defaultTimeout": 5000
}
}
Request Sequencing
Control request execution order in CLI runner:
meta {
name: Authenticate
type: http
seq: 1
}
meta {
name: Get User Data
type: http
seq: 2
}
Requests execute in seq order.
GraphQL Queries
meta {
name: GraphQL Query
type: http
seq: 1
}
post {
url: {{baseUrl}}/graphql
}
body:graphql {
query {
user(id: "{{userId}}") {
id
name
email
}
}
}
Query Parameters
params:query {
page: 1
limit: 10
sort: -createdAt
filter: status:active
}
Git Workflow
Why Git-Native Matters
# Collections stored as text files
.bru/
├── users/
│ ├── get-user.bru
│ └── create-user.bru
└── products/
└── list-products.bru
# Easy to version control
git add .
git commit -m "Update API requests"
git push origin main
# Merge conflicts are manageable
# Review changes in PRs
# Collaborate with team
Collaboration Workflow
# Team member clones collection
git clone https://github.com/team/api-collection.git
cd api-collection
# Install Bruno CLI
npm install -g @usebruno/cli
# Run tests locally
bru run . --env Development
# Make changes
# Add new requests or update existing ones
# Commit and push
git add .
git commit -m "Add payment API endpoints"
git push origin feature/payments
Ignore Sensitive Files
# .gitignore in collection root
.env
.env.local
environments/Production.json
!environments/Production.json.example
secrets/
node_modules/
CI/CD Integration
GitHub Actions
name: API Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Bruno CLI
run: npm install -g @usebruno/cli
- name: Run API tests
run: bru run . --env CI --reporter json --output test-results.json
- name: Upload results
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: test-results.json
GitLab CI
api-tests:
image: node:18
script:
- npm install -g @usebruno/cli
- bru run . --env CI --reporter json --output test-results.json
artifacts:
paths:
- test-results.json
reports:
junit: test-results.json
Local Pre-commit Hook
#!/bin/bash
# .git/hooks/pre-commit
echo "Running API tests..."
bru run . --env Development --failOnError
if [ $? -ne 0 ]; then
echo "API tests failed. Commit aborted."
exit 1
fi
Common Workflows
Testing REST API
# 1. Set up environment
bru run /path/to/collection --env Development
# 2. Check test results
# Tests pass/fail displayed in output
# 3. Generate report
bru run /path/to/collection --env Development --reporter html --output report.html
Load Testing with Parallel Requests
// In pre-request script
for (let i = 0; i < 10; i++) {
bru.setEnvVar('iteration', i);
}
Dynamic Data Generation
// Generate unique email per request
const timestamp = Date.now();
bru.setEnvVar('dynamicEmail', `user_${timestamp}@example.com`);
// Generate random ID
bru.setEnvVar('randomId', Math.floor(Math.random() * 10000));
Chaining Requests
// In post-response script of first request
const data = res.getBody(true);
bru.setEnvVar('userId', data.id);
// Next request uses {{userId}}
Debugging
Enable Verbose Mode
bru run /path/to/collection --verbose
View Request/Response Details
In Bruno GUI:
- Click request
- View “Params” tab for query params
- View “Body” tab for request body
- View “Response” tab for response data
- View “Tests” tab for test results
Console Logging
// In pre-request or post-response scripts
console.log('Variable value:', bru.getEnvVar('baseUrl'));
console.log('Full response:', res.getBody());
console.log('Status code:', res.getStatus());
Network Inspection
// Check response headers
const headers = res.getHeaders();
console.log('All headers:', headers);
// Check response time
console.log('Response time:', res.getResponseTime(), 'ms');
File Structure Best Practices
api-collection/
├── README.md # Documentation
├── .gitignore # Ignore sensitive files
├── bruno.json # Collection metadata
├── environments/ # Environment files
│ ├── Development.json
│ ├── Staging.json
│ └── Production.json
├── globals.json # Global variables
├── auth/
│ ├── login.bru
│ └── refresh-token.bru
├── users/
│ ├── get-all-users.bru
│ ├── get-user-by-id.bru
│ ├── create-user.bru
│ ├── update-user.bru
│ └── delete-user.bru
├── products/
│ ├── list-products.bru
│ └── get-product.bru
└── scripts/
├── test-runner.js
└── helpers.js
Resources
| Resource | URL |
|---|---|
| Official Website | usebruno.com |
| GitHub Repository | github.com/usebruno/bruno |
| Documentation | docs.usebruno.com |
| Download | usebruno.com/downloads |
| Discord Community | discord.gg/usebruno |
| Bru Language Spec | github.com/usebruno/bru |
| API Testing Guide | docs.usebruno.com/api-testing |
| GitHub Issues | github.com/usebruno/bruno/issues |
Tips and Tricks
- Git Diff for Reviews: Since collections are files, use
git diffto review API changes before merging - Environment Templates: Create
.example.jsonfiles for environments to share configuration structure without secrets - Reusable Scripts: Store common test scripts in separate
.jsfiles and reference them - Variable Scope: Collection variables apply globally; request-level variables override them
- Performance: Use
--failOnErrorflag in CI/CD to catch test failures early - Documentation: Add comments in
.brufiles using// comment syntax - Versioning: Include API version in base URL variable for easy switching between versions