Skip to main content

Inherited Variables

The [variables] section in a collection config file makes variables available to every request in that directory and its subdirectories — without declaring them in each request file.

Defining Collection Variables​

# api/api.config.toml

[variables]
base_url = "https://api.example.com"
api_version = "v2"
timeout = "30"

All requests under api/ can use {{base_url}}, {{api_version}}, and {{timeout}} immediately.

Priority in the Resolution Chain​

PrioritySource
1 (Highest)Vault Secrets ({{vault.secret}})
2CLI -V overrides
3Request [variables]
4Suite [variables]
5Explicit -e custom env file
6Hierarchical Directory *.env.toml files (nearest dir > workspace.env.toml)
7 (Lowest)Collection [variables] ← this section (*.config.toml, collection.toml)

If base_url is defined in both a .config.toml and a .env.toml, the .env.toml value wins, as environment configuration overrides baseline collection configuration.

See Variable Precedence for full details.

Self-Referencing (Multi-Pass Resolution)​

Collection variables can reference other variables. Rumour resolves up to 3 passes to handle chains:

[variables]
host = "api.example.com"
base_url = "https://{{host}}" # resolved on pass 1
users_url = "{{base_url}}/users" # resolved on pass 2

Vault References​

[variables]
auth_token = "{{vault.api_token}}"
db_key = "{{vault.db_secret}}"

Set RUMOUR_VAULT_PASS before running. See Vault Variables.

Example​

Let's set up a test workspace to see inherited variables in action against our mock server.

First, initialize a workspace (skip this step if you already created it in a previous tutorial) and scaffold a new users collection using the CLI:

# Skip the init step if you already created the workspace in the previous tutorial
rumour init config_examples
cd config_examples

# Scaffold the new collection
rumour new users -y

This generates the directory structure. Update the generated files to match the layout below:

File Layout​

config_examples/
├── workspace.env.toml
├── config_examples.config.toml
└── users/
└── requests/
└── verify_variables.toml

workspace.env.toml​

base_url = "http://localhost:4000/api/v2"

config_examples.config.toml​

[variables]
service_name = "users-api"
post_id = "1"
post_url = "{{base_url}}/users/{{post_id}}"

users/requests/verify_variables.toml​

name = "verify_inherited_variables"

[request]
method = "GET"
url = "{{post_url}}"

[assert]
status = 200

[assert.json."id"]
equal = 1

[assert.json."username"]
contains = "dev_lead"

post_url is assembled from base_url (from workspace.env.toml) and post_id (from config_examples.config.toml) using multi-pass resolution — no manual construction needed in the request file.

Run​

$ rumour run ./users/requests/verify_variables.toml -v

Output​

$ rumour run ./users/requests/verify_variables.toml -v

GET http://localhost:4000/api/v2/users/1
URL: http://localhost:4000/api/v2/users/1
✓ SUCCESS: ./users/requests/verify_variables.toml (9ms)

╭──────────────────────────────────────────────────────────────────────────╮
│ RUMOUR EXECUTION REPORT │
├──────────────────────────────────────────────────────────────────────────┤
│ Total Requests: 1 │
│ Successful: 1 │
│ Failed: 0 │
│ Skipped: 0 │
│ Success Rate: 100.0% │
│ Total Time: 12ms │
╰──────────────────────────────────────────────────────────────────────────╯

✓ Successful Requests:
- ./users/requests/verify_variables.toml [200] [12ms]

Actionable Recommendations:
→ Run with --json to export this report for your CI/CD pipeline.

Explanation​

When the verify_variables.toml request is executed, the verbose output (-v) shows the resolved URL:

  • post_url (defined in config_examples.config.toml as {{base_url}}/users/{{post_id}}) is resolved dynamically.
  • base_url is resolved from the root environment file workspace.env.toml.
  • post_id is resolved from config_examples.config.toml.

Rumour performs multi-pass variable resolution, resolving the nested placeholders into the final URL http://localhost:4000/api/v2/users/1 before sending the HTTP request.