How Hoppscotch Environment Variables Turn Static Requests into Dynamic Workflows
Hoppscotch’s environment variables let you write one request that works across dev, staging, and prod. Learn how to define, reference, and scope variables, and see a concrete example that switches environments with a single click.
13 Oct 2025, 00:17 UTC

Why Environment Variables Matter in API Testing
When you start a new API project, you quickly run into the same URL, token, or header that changes between dev, staging, and production. Manually editing each request every time you switch environments is tedious and error‑prone. Hoppscotch solves this by letting you define environment variables that are automatically substituted in URLs, headers, and request bodies. The result is a single request definition that works everywhere, as long as the right variables exist.
Defining Variables in Hoppscotch
Variables live in three scopes: workspace, collection, and global. They are simple key/value pairs stored in the browser’s local storage, so they’re available as long as you use the same browser profile.
- Workspace level – Variables that apply to all collections in a workspace. Ideal for project‑wide settings like
baseUrlorapiKey. - Collection level – Overrides workspace variables for a specific group of requests. Useful when a subset of endpoints uses a different base URL.
- Global level – The fallback for any variable not defined elsewhere. Good for defaults like
timeout=30.
To create a variable, click the Variables tab, choose the scope, and add a name/value pair. Hoppscotch provides auto‑complete and syntax validation so you won’t accidentally reference a misspelled variable.
Referencing Variables in Requests
Variables are referenced with double curly braces: {{variableName}}. The substitution happens at send time, so you can mix static text and variables in any part of the request.
GET {{baseUrl}}/users/{{userId}}
Header: Authorization: Bearer {{authToken}}
When you click Send, Hoppscotch replaces each placeholder with its current value before dispatching the HTTP call.
Precedence and Scope Resolution
If the same variable name exists in multiple scopes, Hoppscotch uses the following order:
| Priority | Scope |
|---|---|
| 1 | Collection |
| 2 | Workspace |
| 3 | Global |
Understanding this order prevents accidental overrides. For example, a timeout value set globally will be ignored if a collection defines its own timeout.
Practical Example: Switching Environments
Suppose you have a dev and a prod environment. Create two workspaces, each with a baseUrl variable:
- Workspace Dev Workspace –
baseUrl = https://dev.api.example.com - Workspace Prod Workspace –
baseUrl = https://api.example.com
Copy a request that uses {{baseUrl}} into both workspaces. When you send the request from the dev workspace, Hoppscotch substitutes https://dev.api.example.com. Switching to the prod workspace automatically changes the URL without editing the request.
To verify:
- Open the request URL field and ensure it displays
https://dev.api.example.com/users/{{userId}}in the dev workspace. - Send the request and check the console network tab for the resolved URL.
- Repeat in the prod workspace and confirm the URL changes to
https://api.example.com/users/{{userId}}.
Import/Export for Collaboration
Variables can be exported as JSON from the workspace settings. This file can be version‑controlled and shared with teammates. Importing the JSON into another workspace restores all variables, making cross‑team consistency trivial.
Trade‑Offs and Limitations
- Security – Variables are stored unencrypted in local storage. Never put secrets, API keys, or passwords in them unless you trust the machine.
- Scope Confusion – Name collisions across scopes can lead to unexpected substitutions. Use clear, prefixed names like
dev_baseUrlorprod_baseUrlwhen necessary. - Missing Variables – If a referenced variable is undefined, Hoppscotch aborts the request and highlights the placeholder. Always double‑check that all required variables exist before sending.
Actionable Takeaway
Start by moving all environment‑specific values into workspace variables. Keep global defaults for things that rarely change. Use collection variables only when a subset of endpoints diverges. Export your workspace after configuration so you can share a single JSON file with your team. Finally, remember that while environment variables make requests reusable, they also expose data in the browser; treat them as configuration, not secrets.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.