Request-related Settings
Request-related settings are settings you use to specify attributes of the HTTP request that HttpCommand
will process.
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)) h.Params←'name=dyalog&age=39' ns←⎕NS '' ⋄ ns.(name age)←'dyalog' 39 ⋄ h.Params←ns
|
Details | The interpretation of Params 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.Params , if not empty, is processed
as follows:
|
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' |
Auth
Description | This setting is the authentication/authorization string appropriate for the authentication scheme specified in AuthType . Used along with AuthType, 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.
|
Default | '' |
Example(s) | h.Auth←'my-secret-token'
h.Auth←h.Base64Encode 'userid:password' ⍝ HTTP Basic Authentication |
Details | For HTTP Basic Authentication, Auth should be set to HttpCommand.Base64Encode 'userid:password' .Alternatively, if you provide HTTP Basic credentials in the 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' h.(AuthType Auth)←'basic' (h.Base64Encode 'userid:password') |
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 |
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.