Request-related Settings
Request-related settings are settings you use to specify attributes of the HTTP request that HttpCommand
will process.
Instance Settings
Command
Description | The case-insensitive HTTP command (method) for the request. Command is not limited to standard HTTP methods like GET, POST, PUT, HEAD, OPTIONS, and DELETE, but can be any string provided that the host has implemented support for it. |
Default | 'GET' |
Example(s) | h.Command←'POST' |
URL
Description | The URL for the request. The general format for URL is:
[scheme://][userinfo@]host[:port][/path][?query] At a minimum the URL must specify the host. |
Default | '' |
Example(s) | h.URL←'dyalog.com' |
Details |
A URL has the general format:[scheme://][userinfo@]host[:port][/path][?query]
So, a URL can be as simple as just a host name like 'dyalog.com' or as complex as 'https://username:password@ducky.com:1234/?id=myid&time=1200'
The only mandatory segment is the host ; HttpCommand will infer or use default information when it builds the HTTP request to be sent.
|
Params
Description | The parameters or payload, if any, for the request. Params can be a set of name/value pairs or a character vector that is properly formatted for the ContentType or Command of the
request. See details for more information. |
Default | '' |
Example(s) | The following examples are
equivalent:h.Params←(('name' 'dyalog') ('age' 39)) ns←⎕NS '' ⋄ ns.(name age)←'dyalog' 39 ⋄ h.Params←ns
|
Details | If Params is not empty, its interpretation is dependent on Command and the content type of the
request. The content type is determined by the ContentType setting or
the presence of a content-type header.If Command is 'GET' or 'HEAD' , the request will generally not have a payload in the message body (and hence no specified content type) and Params will be URLEncoded if necessary and appended to the query string of URL .If Command is neither 'GET' nor 'HEAD' and no content type has been
specified, HttpCommand will attempt to infer the content type as follows:
Params is processed based on the content type and inserted as the payload of the request. If the content type is:
|
Headers
Description | The HTTP headers for the request. Specified as one of:
|
Default | By default, HttpCommand will create the following headers if you have not supplied them yourself:Host: the host specified in URL User-Agent: 'Dyalog/HttpCommand 5.0.1' or whatever the version happens to beAccept: '*/*' If the request content type has been specified, HttpCommand will insert an appropriate content-type header.
If the request has content in the request payload, Conga will automatically supply a content-length header.
|
Example(s) | The following examples are equivalent:h.Headers←'accept' 'text/html' 'content-type' 'test/plain'
h.Headers←('accept' 'text/html')('content-type' 'test/plain')
h.Headers←'accept:text/html',(⎕UCS 13 10),'content-type:text/plain'
h.Headers←('accept:text/html')('content-type:text/plain') |
ContentType
Description | This setting is a convenient shortcut for setting the content-type HTTP header of the request. If you happen set both ContentType and a content-type header, ContentType takes precedence.
|
Default | '' |
Example(s) | h.ContentType←'application/json; charset=UTF-8' |
Details | See Content Types for additional information. |
Auth
Description | This setting is the authentication/authorization string appropriate for the authentication scheme specified in AuthType . Used along with AuthType , Auth is a shortcut for setting the authorization HTTP header for requests that require authentication. If Auth is non-empty, HttpCommand will create an 'authorization' header and and set its value to AuthType,' ',Auth . If you happen set both Auth and an authorization header, Auth takes precedence.You may specify an environment variable whose value is to be used for Auth by enclosing the environment variable name in '%' . This helps avoid the need to hardcode credentials in your code.
|
Default | '' |
Example(s) | h.Auth←'my-secret-token'
h.Auth←h.Base64Encode 'userid:password' ⍝ HTTP Basic Authentication h.Auth←'userid' 'password' ⍝ HTTP Basic Authentication |
Details | For HTTP Basic Authentication, Auth can be set to any of
URL as in 'https://username:password@someurl.com' , HttpCommand will automatically generate a proper 'authorization' header.
|
AuthType
Description | This setting is used in conjunction with Auth and is a character vector indicating the authentication scheme. Three common authentication schemes are:
|
Default | '' |
Example(s) | h.AuthType←'Bearer' |
Details |
If AuthType is not set and Auth is set to either a character vector in the form 'userid:password' or a 2-element vector of character vectors as in ('userid' 'password') HttpCommand will infer the AuthType to be 'Basic' .Note: While authentication schemes are supposed to be case insensitive, some servers are not so forgiving and require the authentication scheme to be appropriately cased. |
UseZip
Description | UseZip controls whether the request payload is zipped. Valid values are:
|
Default | 0 |
Details | The ZipLevel setting controls the level of compression when using gzip or deflate encoding. |
ZipLevel
Description | ZipLevel controls the level of compression when using gzip or deflate encoding. Valid values are 0 through 9 . Higher values use a higher degree of compression but also consume more CPU. |
Default | 1 |
Details | The UseZip setting controls which compression algorithm, if any, is used. |
BaseURL
Description | BaseURL can be used when making multiple requests to similar-named endpoints. Set BaseURL to the common root of the URLs that you will be using and then set URL to the remaining portion of the specific URL. BaseURL will be prepended to URL to form the complete URL for the request. Subsequent calls to other endpoints can be made by setting URL . |
Default | '' |
Example(s) |
|
Details | If URL begins with 'http://' or 'https://' , BaseURL will not be prepended to URL . |
Cookies
Description | Cookies is a vector of namespaces, each containing a representation of an HTTP cookie. It contains cookies sent by the host that may be used in a series of requests to the same host. This setting should be considered read-only. |
Default | '' |
Example(s) | (c ← HttpCommand.New 'get' 'github.com').Run [rc: 0 | msg: | HTTP Status: 200 "OK" | ⍴Data: 299959]
≢ c.Cookies 3 ↑c.Cookies.(Name Host ('DD-MMM-YYYY'(1200⌶)Creation)) _gh_sess github.com 05-AUG-2022 _octo github.com 05-AUG-2022 logged_in github.com 05-AUG-2022 |
ChunkSize
Description | A non-zero ChunkSize will make HttpCommand use "chunked" transfer-encoding and send the payload of the request in chunk of ChunkSize bytes. |
Default | 0 meaning do not use "chunked" transfer-encoding |
Details | Using a non-zero ChunkSize will cause HttpCommand to format the payload of the request according to the specification for "chunked" transfer-encoding. This involves breaking the payload into ChunkSize -sized chunks each preceded by the hexadecimal length of the chunk. Note: In the current implementation, the entire, reformatted, payload is sent in a single request to the host. |
Shared Settings
HeaderSubstitution
Description | 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 (
You may also use the delimiters in the |
Default | '' |
Example(s) |
For these examples, assume we have an environment variable named "MyVariable" which has a value of '0123456789' .
Now let's specify a delimiter...
The delimiters do not have to be single characters...
Alternatively, you can use the
|
Details | 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. If no environment variable matches the name between the delimeters, no substitution is performed. |
Name/Value Pairs
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:
- A vector of depth
2
or¯2
with an even number of elements.
('name' 'dyalog' 'age' 39)
- A vector of 2-element vectors,
HttpCommand
will treat each sub-vector as a name/value pair.
(('name' 'dyalog') ('age' 39))
- A 2-column matrix where each row represents a name/value pair.
2 2⍴'name' 'dyalog' 'age' 39
- A reference to a namespace,
HttpCommand
will treat the variables and their values in the namespace as name/value pairs.
ns←⎕NS '' ⋄ ns.(name age)←'dyalog' 39
Note that the names will be alphabetical in the formatted output.