Skip to content

Configuration

t-req is configured via a treq.jsonc file at the root of your workspace. The file supports JSON with comments.

{
// Global variables available to all requests
"variables": {
"baseUrl": "https://api.example.com",
"apiVersion": "v2"
},
// Default request settings
"defaults": {
"timeoutMs": 30000,
"followRedirects": true,
"validateSSL": true,
"proxy": "http://proxy.example.com:8080",
"headers": {
"Accept": "application/json"
}
},
// Cookie handling
"cookies": {
"enabled": true,
"jarPath": ".cookies.json"
},
// Dynamic value resolvers
"resolvers": {
"timestamp": {
"type": "command",
"command": "date +%s"
}
},
// Security settings
"security": {
"allowExternalFiles": false
},
// Environment profiles
"profiles": {
"local": {
"variables": {
"baseUrl": "http://localhost:3000"
}
},
"staging": {
"variables": {
"baseUrl": "https://staging-api.example.com",
"token": "{env:STAGING_TOKEN}"
}
},
"production": {
"variables": {
"baseUrl": "https://api.example.com",
"token": "{env:PROD_TOKEN}"
},
"defaults": {
"timeoutMs": 10000
}
}
}
}

Variables are key-value pairs available to all .http files in the workspace via {{variableName}} syntax.

{
"variables": {
"baseUrl": "https://api.example.com",
"userId": "1",
"token": "my-token"
}
}

Config values support two substitution patterns:

PatternDescriptionExample
{env:VAR}Read from environment variable{env:API_KEY}
{file:path}Read from file contents{file:./secrets/token.txt}

{file:path} supports ~ for home directory expansion and resolves relative paths from the config file location. File contents are trimmed of trailing whitespace and newlines.

Inside .http files, use double-brace syntax:

PatternDescriptionExample
{{variableName}}Simple variable{{baseUrl}}/users
{{nested.key}}Dot notation for nested values{{user.profile.name}}
{{$resolverName()}}Call a resolver{{$timestamp()}}
{{$resolverName(args)}}Resolver with arguments{{$random(0, 100)}}

Example .http file:

GET {{baseUrl}}/users/{{userId}}
Authorization: Bearer {{token}}

Default settings applied to all requests unless overridden:

OptionTypeDefaultDescription
timeoutMsnumber30000Request timeout in milliseconds
followRedirectsbooleantrueAutomatically follow HTTP redirects
validateSSLbooleantrueValidate SSL certificates
proxystringProxy URL for all requests
headersobjectDefault headers applied to every request
OptionTypeDefaultDescription
enabledbooleanEnable automatic cookie handling
jarPathstringPath to persistent cookie jar file

When enabled, cookies from Set-Cookie response headers are stored and sent with subsequent requests automatically.

Resolvers provide dynamic values in .http files via {{$name()}} syntax.

Runs an external command and uses its stdout as the value:

{
"resolvers": {
"timestamp": {
"type": "command",
"command": "date +%s"
},
"uuid": {
"type": "command",
"command": "uuidgen"
}
}
}

Use in a .http file:

POST {{baseUrl}}/events
Content-Type: application/json
{
"id": "{{$uuid()}}",
"timestamp": "{{$timestamp()}}"
}

Command resolvers act as an external plugin system — any executable that writes to stdout can provide values.

Profiles let you switch between environments. Each profile can override variables, defaults, cookies, and resolvers from the root config.

{
"variables": {
"baseUrl": "https://api.example.com"
},
"profiles": {
"local": {
"variables": {
"baseUrl": "http://localhost:3000"
}
},
"staging": {
"variables": {
"baseUrl": "https://staging.example.com",
"token": "{env:STAGING_TOKEN}"
}
}
}
}

Activate a profile via the CLI:

Terminal window
treq run requests/api.http --profile staging

Or select one in the TUI.

Profile values are merged on top of the root configuration. Only the fields you specify in a profile are overridden.

OptionTypeDefaultDescription
allowExternalFilesbooleanfalseAllow {file:path} to reference files outside the workspace

By default, {file:path} substitutions are restricted to files within the workspace root. Set allowExternalFiles: true to allow references to files anywhere on the filesystem.