Hoppscotch Environment Variable Scope: A Practical Guide
Quick answer: Hoppscotch gives you five variable scopes, and when two variables share a name, the narrowest scope wins. Resolution runs Request, then Collection, then Predefined, then Environment, then Global, so a request-level value overrides a global one and a red name means no scope produced a value. The five scopes and the job each one does Hoppscotch treats anything wrapped in double angle…
Hoppscotch, a desktop tool for creating and managing API requests, offers five variable scopes with a clear hierarchy. From narrowest to broadest, these scopes are Request, Collection, Predefined, Environment, and Global, with the order of precedence determined by color-coded indicators. When a variable name collides between scopes, the closest definition takes priority.
Request variables are scoped to a single request, Collection variables apply to a collection and its child folders, Predefined variables are generated at runtime and prefixed with a dollar sign, Environment variables are tied to a selected environment, and Global variables have the widest scope, applying to every workspace. Not resolving to any scope results in a red name, signaling that no value was found.
Regular variables are visible and synced across workspaces, while secret variables remain hidden, not synced, and are populated at runtime. When exporting an environment, secret values are omitted. Variables can be written at the environment level or globally, with the experimental hopp.env.global.set() function targeting the global scope.
Reading variables uses the get() function, which resolves nested references, or getRaw() for the stored string. When writing variables, pw.env.set() targets the currently selected environment, while hopp.env.active.set() targets the active environment. In summary, choosing the appropriate variable scope is crucial for efficient API request management, with the rule of "narrow beats wide" guiding best practices.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to