- Published on
Nested environment variables in Postman
- Authors
- Name
- David Jimenez
In Postman, environment nested variables look something like this:
The variable {{mock_url}} contains another one, {{environment}}.
{{environment}} defines the subdomain for the URL that we are using in our tests. In the code snippet below, we see that Postman correctly resolved the nested variable to generate a URL with the development
subdomain:
Why would we want to do this?
Many organizations test and release their code using different environments. Three common environments are development, staging, and production. Nested variables could be good way to run a collection against the appropriate target.
Could this be done in other ways? Certainly. We can introduce more variables:
Instead of having a single variable containing the whole URL, we could have two: one for the environment; the other, for the domain. However, what would happen if we use the URL extension, rather than the subdomain, to distiguish between environments? If we were starting from scratch, we could introduce a third variable. But what if we already have several collections with multiple endpoints that only use the first two variables we defined?