Create professional Bruno REST API endpoint configurations with proper authentication, environment setup, and documentation...
Bruno-specific patterns for creating .bru endpoint files. Assumes familiarity with REST conventions.
Development (Local.bru):
vars {
baseUrl: http://localhost:3001
linkId:
apiKey: dev_api_key_change_in_production
}
Production/Staging โ use vars:secret for sensitive data:
vars {
baseUrl: https://api.yourdomain.com
linkId:
}
vars:secret [
apiKey
]
Set auth once in collection.bru, then inherit in all endpoints:
auth {
mode: bearer
}
auth:bearer {
token: {{apiKey}}
}
Individual endpoints inherit with auth: inherit:
post {
url: {{baseUrl}}/api/v1/resources
body: json
auth: inherit
}
Override per-endpoint only when auth differs from the collection.
meta {
name: "Create Resource"
type: http
seq: 1
}
post {
url: {{baseUrl}}/api/v1/resources
body: json
auth: inherit
}
body:json {
{
"resource": {
"field1": "value1",
"field2": "value2"
}
}
}
params:path {
id: {{resourceId}}
}
params:query {
page: 1
limit: 20
sort: created_at
order: desc
}
Post-response โ extract data for subsequent requests:
script:post-response {
if (res.status === 201 && res.body && res.body.id) {
bru.setVar("resourceId", res.body.id);
}
}
Pre-request โ generate dynamic data:
script:pre-request {
const timestamp = Date.now();
bru.setVar("uniqueEmail", `test-${timestamp}@example.com`);
}
Key difference:
bru.setVar() โ runtime variables (temporary, current collection run only)bru.setEnvVar() โ environment variables (persists, visible in Environment tab)Use bru.setVar() for ephemeral values like extracted IDs from test runs.
docs {
Create a new resource in the system.
**Required Fields:**
- field1: Description
- field2: Description
**Optional Fields:**
- optional_field: Description
}
Bruno Collection/
โโโ Environments/
โ โโโ Local.bru
โ โโโ Staging.bru
โ โโโ Production.bru
โโโ Authentication/
โ โโโ Login.bru
โ โโโ Refresh Token.bru
โโโ Resources/
โ โโโ List Resources.bru
โ โโโ Get Resource.bru
โ โโโ Create Resource.bru
โ โโโ Update Resource.bru
โ โโโ Delete Resource.bru
โโโ Health/
โโโ Health Check.bru