Skip to content

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'
h.URL←'https://user:pwd@adomain.com:8080/apath/endpoint?name=Drake
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.
  • scheme - if supplied, it must be either 'http', or 'https' for a secure connection. If not supplied, HttpCommand will use 'http' unless you have specified the default HTTPS port (443) or provided SSL certificate parameters.
  • userinfo - used for HTTP Basic authentication. HTTP Basic authentication has generally been deprecated, but may still be supported by some hosts. If userinfo is supplied, HttpCommand will create a proper Base64-encoded authorization header.
  • host - the host/domain for the request
  • port - if not supplied, HttpCommand will use the default HTTP port (80) unless the HTTPS scheme is used or certificate parameters are specified in which case the default HTTPS port (443) is used.
  • path - the location of the resource within the domain. If not supplied, it's up to the domain's server to determine the default path.
  • query - the query string for the request. If the HTTP method for the request is 'GET' or 'HEAD' and request parameters are specified in Params, HttpCommand will properly format them and append them to the query string. If you choose to supply query string parameters directly, they should be properly URLencoded. (see URLencode)

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:
  • If Command is neither 'GET' nor 'HEAD' and no content type has been specified, HttpCommand will specify the default content type of 'x-www-form-urlencoded'.
  • If the content type of the request is specified, HttpCommand will set the formatted Params as the payload of the request. Params is formatted based on the content type:
    • 'x-www-form-urlencoded': Params will be URLEncoded using UrlEncode.
    • 'application/json':
      • If Params is a character vector that is a valid JSON representation,it is left unaltered.
      • Otherwise Params will be converted to JSON format using 1 ⎕JSON.
      • In the case where Params is an APL character vector that is also valid JSON, you should JSON encode it prior to setting Params. For example, if you have the character vector '[1,2,3]' and you want it treated as a string in JSON and not thenumeric array [1,2,3], you should process it yourself using 1 ⎕JSON.
    • For any other content type, it is the responsibility of theuser to format Params appropriately for the content type.
  • If Command is either 'GET' or 'HEAD' (and no content type has been specified), HttpCommand will append the formatted Params to the query string of URL. In this case, Params is formatted as follows:
    • If Params is a simple array:
      • If P←(∊⍕Params) consists entirely of valid URLEncoded characters, P is appended to the query string. (see ValidFormUrlEncodedChars)
      • Otherwise HttpCommand will URLEncode P and append the result to the query string.

Headers

Description The HTTP headers for the request. Specified as one of:
  • a set of name/value pairs.
  • a character vector of of one or more name/value pairs in the form 'name:value' separated by CRLF (⎕UCS 13 10).
  • a vector of character vectors, each in the form 'name:value'
DefaultBy 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 be
Accept: '*/*'

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:
  • 'basic' for HTTP Basic Authentication
  • 'bearer' for OAuth 2.0 token authentication
  • 'token' for other token-based authentication schemes such as GitHub's Personal Access Token scheme
Other values may be used as necessary for your particular HTTP request.
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.