|
1 | 1 | Request-related settings are settings you use to specify attributes of the HTTP request that `HttpCommand` will process.
|
2 |
| -## Settings |
| 2 | +## Instance Settings |
3 | 3 | ### `Command`
|
4 | 4 | <table><tr>
|
5 | 5 | <td>Description</td>
|
@@ -220,6 +220,57 @@ If <code>AuthType</code> is not set and <code>Auth</code> is set to either a cha
|
220 | 220 | <code> logged_in github.com 05-AUG-2022</code><br/>
|
221 | 221 | </td></tr></table>
|
222 | 222 |
|
| 223 | +## Shared Settings |
| 224 | +### `HeaderSubstitution` |
| 225 | +<table><tr> |
| 226 | +<td>Description</td> |
| 227 | +<td><p>In the following text, the phrase "environment variable" is taken to mean either an environment variable or a Dyalog configuration setting as both of these are retrieved using the same technique (<code>2 ⎕NQ '.' 'GetEnvironment')</code>.</p><p><code>HeaderSubstitution</code> provides a shorthand technique to inject environment variable values into the request's HTTP header names and values. If <code>HeaderSubstitution</code> is <code>''</code> (the default), no substitution is done. When <code>HeaderSubstitution</code> has a non-empty value, it denotes the beginning and ending delimiteres between which you may use the name of an enviroment variable. If <code>HeaderSubstitution</code> is a single character, that character is used as both the beginning and ending delimiter.</p> |
| 228 | +<p>You may also use the delimiters in the <a href="#auth"><code>Auth</code></a> setting as <code>Auth</code> is used to format the HTTP Authorization header.</p> |
| 229 | +</td></tr> |
| 230 | +<tr><td>Default</td> |
| 231 | +<td><code>''</code></td></tr> |
| 232 | +<tr><td>Example(s)</td><td> |
| 233 | +For these examples, assume we have an environment variable named "MyVariable" which has a value of <code>'0123456789'</code>. <pre><code> HttpCommand.HeaderSubstitution←'' ⍝ no substitutions done |
| 234 | + h←HttpCommand.New 'get' 'someurl.com' |
| 235 | + 'name' h.SetHeader '%MyVariable%' |
| 236 | + h.Show |
| 237 | + GET / HTTP/1.1 |
| 238 | +name: %MyVariable% |
| 239 | +Host: someurl.com |
| 240 | +User-Agent: Dyalog-HttpCommand/5.7.0 |
| 241 | +Accept: */* |
| 242 | +Accept-Encoding: gzip, deflate</code></pre> |
| 243 | +<p>Now let's specify a delimiter...</p> |
| 244 | +<pre><code> HttpCommand.HeaderSubstitution←'%' ⍝ specify a delimiter |
| 245 | + h.Show |
| 246 | +GET / HTTP/1.1 |
| 247 | +name: 0123456789 |
| 248 | +Host: someurl.com |
| 249 | +User-Agent: Dyalog-HttpCommand/5.7.0 |
| 250 | +Accept: */* |
| 251 | +Accept-Encoding: gzip, deflate |
| 252 | +</code></pre> |
| 253 | +<p>The delimiters do not have to be single characters...</p> |
| 254 | +<pre><code> HttpCommand.HeaderSubstitution←'env:[' ']' |
| 255 | + 'name' h.SetHeader 'env:[MyVariable]' |
| 256 | + h.Show |
| 257 | +GET / HTTP/1.1 |
| 258 | +name: 0123456789 |
| 259 | +Host: someurl.com |
| 260 | +User-Agent: Dyalog-HttpCommand/5.7.0 |
| 261 | +Accept: */* |
| 262 | +Accept-Encoding: gzip, deflate</code></pre> |
| 263 | +<p>Alternatively, you can use the <code>GetEnv</code> method to retrieve environment variables and/or Dyalog configuration settings.</p> |
| 264 | +<pre><code> 'name' h.SetHeader GetEnv 'MyAPIKey' |
| 265 | +</code></pre> |
| 266 | +</td></tr> |
| 267 | +<tr><td>Details</td> |
| 268 | +<td><p>Many web services require an API key. It is generally considered bad practice to hard-code such API keys in your application code. Storing the keys as environment variables allows them to be retrieved more securely.</p> |
| 269 | +<p>If no environment variable matches the name between the delimeters, no substitution is performed.</p> |
| 270 | +</td></tr> |
| 271 | +</table> |
| 272 | + |
| 273 | + |
223 | 274 |
|
224 | 275 | ## Name/Value Pairs
|
225 | 276 | `Params`, for an appropriate content type, and `Headers` can be specified as name/value pairs. `HttpCommand` gives you some flexibility in how you specify name/value pairs. You may use:
|
|
0 commit comments