Environment Variables: Dev, Staging, and Production
How Environments let a Collection stay the same while its variables swap between dev, staging, and production.
The same request usually needs to run against more than one place — your local machine while you're building, staging before a release, production once it's live. Rewriting the URL and tokens by hand every time you switch is exactly what Environments exist to remove.
What an environment is
An environment is a named set of variables — a base URL, an API key, whatever else a request references — that you can swap in and out without touching the request itself. Write a request once against {{baseUrl}}/users, and switching environments changes what {{baseUrl}} actually resolves to.
AlleForge supports this at two levels:
- Environment variables — the set you swap between (dev, staging, production, or however you've split things up).
- Collection-level variables — values scoped to one collection, useful for things that don't change per environment but still shouldn't be hardcoded into every request.
A typical switch
- Build a request using a variable instead of a literal value —
{{baseUrl}}instead ofhttps://api-staging.example.com. - Define that variable once in each environment you use (dev, staging, prod), pointing at the right host each time.
- Switch the active environment. Every request using
{{baseUrl}}now resolves against the new one — nothing about the request itself changes.
Where this matters most
Two places this shows up constantly:
- Authentication — a bearer token or API key is almost always environment-specific. Store it as an environment variable once, and every request that inherits auth from the collection picks it up automatically. See Authentication for how inherited auth works.
- Testing localhost or private APIs — if you're pointing
{{baseUrl}}athttp://localhost:3000instead of a public host, you'll also need AlleForge Agent running, since a browser tab can't reachlocalhostor an internal network on its own.
What this isn't
Environments swap values — they don't isolate collections from each other or add access control. Who can see or edit an environment follows the same workspace roles as the collection it belongs to.
See this in AlleForge
Open API Testing