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
2Request [variables]
3Collection [variables] ← this section
4CLI -V overrides
5Directory .env.toml files
6 (Lowest)-e custom env file

If base_url is defined in both a .config.toml and a .env.toml, the .config.toml value wins.

See [Variable Precedence](/ environments/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](/ variables/vault-variables).

Example

The following example was verified against the local mock server.

File Layout

config_examples/04_inherited_variables/
├── workspace.env.toml
├── api.config.toml
└── verify_variables.toml

workspace.env.toml

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

api.config.toml

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

verify_variables.toml

name = "verify_inherited_variables"

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

[assert]
status = 200

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

[assert.json."email"]
contains = "test.com"

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

Run

rumour run ./config_examples/04_inherited_variables/verify_variables.toml -v

Output

~/workspace/testing main ❯ rumour run ./config_examples/04_inherited_variables/verify_variables.toml -v
GET http://localhost:4000/api/v2/users/1
URL: http://localhost:4000/api/v2/users/1
✓ SUCCESS: /home/bugsfounder/workspace/testing/config_examples/04_inherited_variables/verify_variables.toml (1ms)
✓ /home/bugsfounder/workspace/testing/config_examples/04_inherited_variables/verify_variables.toml → PASS (1 Pass, 0 Fail, 0 Skip)
╭──────────────────────────────────────────────────────────────────────────╮
│ RUMOUR EXECUTION REPORT │
├──────────────────────────────────────────────────────────────────────────┤
│ Total Requests: 1
│ Successful: 1
│ Failed: 0
│ Skipped: 0
│ Success Rate: 100.0% │
│ Total Time: 2ms │
╰──────────────────────────────────────────────────────────────────────────╯

✓ Successful Requests:
- /home/bugsfounder/workspace/testing/config_examples/04_inherited_variables/verify_variables.toml [200] [2ms]

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 api.config.toml as {{base_url}}/users/{{post_id}}) is resolved dynamically.
  • base_url is resolved from the parent directory's workspace.env.toml.
  • post_id is resolved from api.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.