Add a file called http-client.env.json
in the same directory as the .http
file. By default, this file is set to check into source control.
This file can be left blank, if you don’t have any values checked in.
{ }
Add another file called http-client.env.json.user
in the same directory. This is where the secret values go in. By default, this file is set not to check into source control.
In this file you can set the secrets under an environment root,
{
"dev": {
"Username": "myusername1",
"Password": "mypassword1"
},
"prod": {
"Username": "myusername2",
"Password": "mypassword2"
}
}
Now in the .http
file access the defined variable using {{ }}
,
In this example, the environment variable file values are read into .http
file variables,
@UsernameVar = {{Username}}
@PasswordVar = {{Password}}
then used as needed,
POST {{MyAuth.Auth_HostAddress}}/api/v1/auth/login
Content-Type: application/json
{
"username": "{{UsernameVar}}",
"password": "{{PasswordVar}}"
}
Finally you can switch environments from the defined list of environemnts in the top right corner of Visual Studio .http
file editor,