Variable precedence between shared and private HTTP client environments
0 reputation · 29 Sept 2024, 23:24 UTC
0 reputation · 29 Sept 2024, 23:24 UTC
Testing an integration against a sandbox without committing production credentials is a common use case for the IntelliJ-based HTTP client. The documented credential-free pattern uses a shared http-client.env.json for non-secret defaults and a local http-client.private.env.json for secrets that should not be committed.
The design relies on environment selection in the request editor and on the IDE keeping private files out of version control. It is unclear whether the private file is guaranteed to be ignored by VCS or only offered for ignore on creation, and whether that behavior is enforced across workspaces.
Precedence is also uncertain. When the same variable name is defined in both the shared and private files for the active environment, the value actually sent is not obvious from the editor gutter alone and may be version-sensitive.
Which value does the HTTP client use for duplicate keys, private or shared? Is the private environment file automatically excluded from version control, or does the ignore depend on an opt-in prompt? Which IDE documentation confirms precedence for a specific build?
34775 reputation · 30 Sept 2024, 01:16 UTC
For the active environment the IntelliJ HTTP client resolves a variable that appears in both http-client.env.json (shared) and http-client.private.env.json (private) by using the private file's value. This precedence is the documented behavior for IDE builds from 2023.3 onward but it may differ in earlier or later major releases.
The private environment file is not automatically ignored by version control. When first created the IDE shows a prompt offering to add http-client.private.env.json to .gitignore. Dismissing the prompt or using a different VCS leaves the file tracked unless you add the ignore entry manually.
http-client.env.json is intended for project-wide defaults and is safe to commit to version control.http-client.private.env.json is designed to remain local to the IDE user and is not intended for shared or committed storage..gitignore entry for the private file is added only when the IDE prompts on first creation..http request file and show the Variables pane (View Tool Windows HTTP Client Variables). The pane lists each resolved variable with the source file name making it easy to confirm which file's value is active for duplicate keys.API_BASE in both http-client.env.json and http-client.private.env.json under the same environment key. Run the request and observe the rendered value in the Variables pane it should show the private file's value.http-client.private.env.json open .gitignore and verify that a line http-client.private.env.json exists. If it is missing add it manually.One diagnostic detail that changes the recommendation: if you are on an IntelliJ IDEA version earlier than 2023.3 or a preview build the precedence order might be reversed or undefined. Please confirm the exact IDE build (Help About) so the advice can be scoped to that release.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.