Reading Environment Variables¶
Responses can include any environment variable. The following example starts up mock with a custom environment variable and includes its variable in an endpoint’s response.
$ FOO=BAR mock serve -c path/to/config.json
And then the configuration file:
{
"endpoints": [
{
"route": "foo/bar",
"method": "GET",
"response": "The value of 'FOO' is ${FOO}."
}
]
}
Let’s accomplish the same but now using command-line parameters instead of configuration file. Note here the usage of single-quotes around the response string, because we don’t want these variables to be processed by the shell program, but by mock instead:
$ export FOO=bar
$ mock serve \
+ --route 'foo/bar' \
+ --response 'The value of FOO is ${FOO}.'