跳转到内容

Use environments and variables

此内容尚不支持你的语言。

A request names values as {{name}}. They come from the file itself, from an environment file next to it, or from what a response handler script stored. Environments with a private file: Works.

@host = https://api.example.com
@limit = 10
GET {{host}}/products?limit={{limit}}
Authorization: Bearer {{token}}

Each {{name}} is resolved in this order: variables of the file (@name = value; a later definition wins), then the chosen environment, then the globals that response handler scripts set. Variables may use other variables, and spaces inside the braces are allowed: {{ host }}.

A request with an unresolved name is never sent, whichever way you run it. Output lists the names that have no value, including an unclosed {{.

These names produce a new value on every use (unless the file or environment defines the same name):

Variable Value
{{$uuid}}, {{$random.uuid}} a random UUID (version 4)
{{$timestamp}} the Unix time in seconds
{{$isoTimestamp}} the time in UTC, such as 2026-12-04T09:30:00Z
{{$randomInt}} a whole number from 0 to 1000
{{$random.integer(from, to)}} a whole number from from up to, not including, to; without arguments 0 to 999
{{$random.float(from, to)}} a decimal number from from up to, not including, to; without arguments 0 to under 1000
{{$random.alphabetic(n)}} n letters
{{$random.alphanumeric(n)}} n letters, digits and _
{{$random.hexadecimal(n)}} n hexadecimal digits
{{$random.email}} a random address at example.com

n is 1 to 10,000. Arguments that do not fit, such as from not below to, leave the name unresolved, so the request is not sent.

Put http-client.env.json next to the .http file or in a folder above it, up to the project root. Each top-level key is an environment:

{
"$shared": { "version": "v2" },
"local": { "host": "http://localhost:8080" },
"staging": { "host": "https://staging.example.com" }
}
  • $shared applies to every environment unless the environment defines the same name.
  • Strings, numbers and booleans become values; nested objects are skipped.
  • The nearest folder that has an environment file wins.

Put tokens and passwords in http-client.private.env.json beside it, with the same shape:

{
"local": { "token": "local-dev-token" },
"staging": { "token": "…" }
}

Private values win over shared ones. They are sent to the server and shown to you, but never written to a file by Ferris IDEA, and the agent log shows {{token}} in their place.

When the files define one environment, it is used. With several, choose one:

  1. Send a request from the file (or open the Services tool window).
  2. Click Env: none ▾ in the Services window. The HTTP environment list opens.
  3. Click the environment. The choice holds for that .http file until you close the window; choosing sends nothing.

Until you choose, a request that needs an environment variable is not sent, and the status bar and Output say “Not sent: choose an HTTP environment: local, staging”. A request that uses no environment variable goes without one. Run All asks once for the whole file.

Agents pass environment to the tools. Without the right secret-read, private values are masked as {{name}} in what the tools return and listed under masked, and the private file cannot be read. With several environments and none given, a call is refused with the names the files define.

  • http_requestsreadsRequests of a .http file: name, line, method, URL, headers and body with variables resolved from the file, the environment of http-client.env.json/http-client.private.env.json and env, plus unresolved names, settings (# @no-redirect, # @timeout N), body_files (not read), notes on parts never sent, and script: the response handler with status needs approval (only a person approves it, in the window), approved or refused.
  • send_http_requestchangesdry run by defaulthttpSend one request of a .http file.