Variable Interpolation
Variable interpolation in Bruno allows you to use variables in your requests using the {{variableName}} syntax. Let's explore how interpolation works with different data types.
Basic Interpolation
Strings
// Setting a string variable
bru.setVar("greeting", "Hello World");
// Using in request
GET http://api.example.com/{{greeting}}
// Interpolates to: http://api.example.com/Hello World
Numbers
// Setting a number variable
bru.setVar("userId", 123);
// Using in request
GET http://api.example.com/users/{{userId}}
// Interpolates to: http://api.example.com/users/123
Booleans
// Setting a boolean variable
bru.setVar("isActive", true);
// Using in request body
{
"active": {{isActive}}
}
// Interpolates to: { "active": true }
Referencing variables inside other variables
Interpolation is recursive: if a variable's value contains another {{...}} placeholder, Bruno resolves the inner reference too. This lets you compose one variable from others directly in the Vars editor, without a pre-request script.
// Set variables that reference each other
bru.setVar("host", "api.example.com");
bru.setVar("baseUrl", "https://{{host}}/v1");
GET {{baseUrl}}/users
// Interpolates to: https://api.example.com/v1/users
The same works for values entered as environment, collection, or folder variables in the UI. Bruno keeps resolving until every placeholder is replaced or an unknown variable is left in place. Cycles (for example, a → {{b}} and b → {{a}}) are detected and the last unresolved placeholder is left as-is.
Object Interpolation
You can access object properties using dot notation. Here's how to work with objects containing different data types:
// Define your object with multiple data types
const userProfile = {
username: "john_doe", // string
accountId: 12345, // number
isVerified: true, // boolean
preferences: { // nested object
theme: "dark",
notifications: true
}
};
// Set the object as a variable
bru.setVar("user", userProfile);
// Using in request body
{
"username": "{{user.username}}",
"verified": {{user.isVerified}},
"preferences": {{user.preferences}},
}
// Interpolates to:
// {
// "username": "john_doe",
// "verified": true,
// "preferences": {
// "theme": "dark",
// "notifications": true
// }
// }
Array Interpolation
// Define your arrays
const technologies = ["REST", "GraphQL", "gRPC"];
const settings = [
{ port: 3000, env: "dev" },
{ port: 8080, env: "prod" }
];
// Set arrays as variables
bru.setVar("apiTypes", technologies);
bru.setVar("configs", settings);
// Using array elements in request
{
// Simple array access
"primaryAPI": "{{apiTypes[0]}}", // "REST"
"alternativeAPI": {{apiTypes}},
// Accessing object properties in arrays
"devPort": {{configs[0].port}}, // 3000
"prodEnv": {{configs}},
// Using multiple array elements
"supported": {
"apis": ["{{apiTypes[0]}}", "{{apiTypes[1]}}"],
}
}
// Interpolates to:
// {
// "primaryAPI": "REST",
// "alternativeAPI": [
// "REST",
// "GraphQL",
// "gRPC"
// ]
// "devPort": 3000,
// "prodEnv": [
// {
// "port": 3000,
// "env": "dev"
// },
// {
// "port": 8080,
// "env": "prod"
// }
// ]
// "supported": {
// "apis": ["REST", "GraphQL"],
// }
// }
Date Interpolation
// Bruno v2.2.0+
bru.setVar("timestamp", new Date());
// Using in request
{
"createdAt": "{{timestamp}}"
}
// Interpolates to:
// {
// "createdAt": "2025-04-23T13:57:56.341Z"
// }
Practical Examples
API Authentication
bru.setVar("authConfig", {
apiKey: "your-api-key",
secret: "your-secret"
});
// In request headers
headers {
"X-API-Key": "{{authConfig.apiKey}}",
"X-Secret": "{{authConfig.secret}}"
}
Dynamic Query Parameters
bru.setVar("searchParams", {
limit: 10,
offset: 0,
filter: "active"
});
// In URL
GET http://api.example.com/users?limit={{searchParams.limit}}&offset={{searchParams.offset}}&filter={{searchParams.filter}}
Request Body with Mixed Types
bru.setVar("product", {
name: "Bruno Pro",
price: 99.99,
features: ["Git Integration", "Offline First"],
metadata: {
version: "2.2.0",
released: new Date()
}
});
// In request body
{
"productName": "{{product.name}}",
"price": {{product.price}},
"firstFeature": "{{product.features[0]}}",
"releaseDate": "{{product.metadata.released}}"
}
bru.setVar() are available throughout your collection's scope. Use them to make your requests more dynamic and maintainable.