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.

Plugins extend t-req with custom hooks for request/response processing, authentication, assertions, and more. The plugins key is a top-level array of plugin references.

{
"plugins": [
"@t-req/plugin-assert",
["@t-req/plugin-oauth2", { "provider": "github" }],
"file://./plugins/custom.ts",
{
"command": ["node", "./plugins/external.js"],
"timeoutMs": 5000
}
]
}
SourceFormatExample
npm package"package-name""@t-req/plugin-assert"
npm package with options["package-name", { options }]["@t-req/plugin-oauth2", { "provider": "github" }]
Local file"file://./path""file://./plugins/custom.ts"
Subprocess{ "command": [...] }{ "command": ["node", "./plugin.js"] }

A string referencing an installed npm package. The package must export a valid t-req plugin.

A [packageName, options] tuple. The options object is passed to the plugin’s factory function.

A file:// URL pointing to a local .ts or .js file that exports a plugin. Relative paths resolve from the project root. By default, the file must be within the project root — see security.allowPluginsOutsideProject to allow external paths.

An object with a command array and optional configuration:

OptionTypeDefaultDescription
commandstring[]Command to spawn (e.g., ["node", "./plugin.js"])
configobjectPlugin-specific config sent during initialization
timeoutMsnumberPer-request timeout in milliseconds
startupTimeoutMsnumberInitialization timeout in milliseconds
maxRestartsnumberAuto-restart limit
gracePeriodMsnumberShutdown grace period in milliseconds
envobjectAdditional environment variables

Plugins can also be specified per profile. Profile plugins are appended to the base plugin list:

{
"plugins": ["@t-req/plugin-assert"],
"profiles": {
"production": {
"plugins": ["@t-req/plugin-logging"]
}
}
}

If a profile plugin has the same name and instance ID as a base plugin, the profile version overrides it.

OptionTypeDefaultDescription
allowExternalFilesbooleanfalseAllow {file:path} to reference files outside the workspace
allowPluginsOutsideProjectbooleanfalseAllow file:// plugins to load from paths outside the project root
pluginPermissionsobjectPermission overrides for plugins (see below)

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.

When false (the default), file:// plugin paths must resolve to a location within the project root (symlinks are resolved before checking). Set to true to load plugins from anywhere on the filesystem.

Controls which capabilities plugins receive. Plugins declare the permissions they need; this setting restricts or overrides those declarations.

Available permissions:

PermissionGrants
secretsAccess to resolvers that read secrets (Vault, SSM, env vars)
networkOutbound HTTP requests (OAuth refresh, telemetry)
filesystemRead/write files outside the project root
envRead process.env
subprocessSpawn child processes
enterpriseAccess enterprise context (org, user, session data)

Use default to set a baseline for all plugins, and per-plugin keys to override:

{
"security": {
"pluginPermissions": {
"default": ["network"],
"@t-req/plugin-oauth2": ["secrets", "network", "env"],
"my-local-plugin": ["filesystem", "subprocess"]
}
}
}

If no pluginPermissions config is present, plugins receive all the permissions they declare.