You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/test/http-files.md
+27-3Lines changed: 27 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ This article contains documentation for:
21
21
*[The `.http` file syntax](#http-file-syntax).
22
22
*[How to create an `.http` file](#create-an-http-file).
23
23
*[How to send a request from an `.http` file](#send-an-http-request).
24
-
*[Where to find `.http` file options that can be configured.](#http-file-options).
24
+
*[Where to find `.http` file options that can be configured](#http-file-options).
25
25
*[How to create requests in `.http` files by using the Visual Studio 2022 **Endpoints Explorer**](#use-endpoints-explorer).
26
26
27
27
The `.http` file format and editor was inspired by the Visual Studio Code [REST Client extension](https://marketplace.visualstudio.com/items?itemName=humao.rest-client). The Visual Studio 2022 `.http` editor recognizes `.rest` as an alternative file extension for the same file format.
@@ -166,9 +166,33 @@ Visual Studio displays warnings in the following situations:
166
166
167
167
A variable defined in an environment file can be the same as one defined in the `.http` file, or it can be different. If a variable is defined in both the `.http` file and the environment file, the value in the `.http` file overrides the value in the environment file.
168
168
169
+
## Shared variables
170
+
171
+
`$shared` is a special environment name for values that are the same for multiple environments. For example, consider the following environment file (`http-client.env.json`):
172
+
173
+
```json
174
+
{
175
+
"$shared": {
176
+
"HostAddress": "https://localhost:7293"
177
+
},
178
+
"dev1": {
179
+
"username": "dev1user"
180
+
},
181
+
"dev2": {
182
+
"username": "dev2user"
183
+
},
184
+
"staging": {
185
+
"username": "staginguser",
186
+
"HostAddress": "https://staging.contoso.com"
187
+
}
188
+
}
189
+
```
190
+
191
+
In the preceding example, the `$shared` environment defines the `HostAddress` variable with the value `localhost:7293`. The `HostAddress` variable with the value `localhost:7293` functions as a default for environments that don't define a `HostAddress`. When the `dev1` or `dev2` environment is defined, the value for `HostAddress` comes from the `$shared` environment because `dev1` and `dev2` don't define a `HostAddress` variable. When the `staging` environment is defined, the value for `HostAddress` is set to `https://staging.contoso.com`, overriding the `$shared` default.
192
+
169
193
## User-specific environment files
170
194
171
-
A user-specific value is any value that an individual developer wants to test with but doesn’t want to share with the team. Since the `http-client.env.json` file is checked in to source control by default, it wouldn’t be appropriate to add user-specific values to this file. Instead, put them in a file named `http-client.env.json.user`located in the same folder as the `http-client.env.json` file. Files that end with `.user`should be excluded from source control by default when using Visual Studio source control features.
195
+
A user-specific value is any value that a developer wants to test with but doesn't want to share with the team. The `http-client.env.json` file is checked in to source control by default, therefore, ***DO NOT***add user-specific values to this file. Rather, add user-specific values in a file named `http-client.env.json.user`. The `http-client.env.json.user` file is located in the same folder as the `http-client.env.json` file. Files that end with `.user`are excluded from source control by default when using Visual Studio source control features.
172
196
173
197
When the `http-client.env.json` file is loaded, Visual Studio looks for a sibling `http-client.env.json.user` file. If a variable is defined in an environment in both the `http-client.env.json` file and the `http-client.env.json.user` file, the value in the `http-client.env.json.user` file wins.
174
198
@@ -330,7 +354,7 @@ GET {{HostAddress}}{{Path}}
330
354
X-UserName: {{$processEnv USERNAME}}
331
355
```
332
356
333
-
If you try to use `$processEnv` to access an environment variable that doesn’t exist, the `.http` file editor displays an error message.
357
+
If you try to use `$processEnv` to access an environment variable that doesn't exist, the `.http` file editor displays an error message.
0 commit comments