HttpClient Utility

HTTP client utility

Use this utility to make an HTTP-callout.

Example of usage:

let header = new Headers();
header.addHeader("Content-Type", "application/json");
header.addHeader("Accept-Language", "ja");

let payload = new Parameters();
payload.addParameter("scope", ["openid", "profile", "email"]);
payload.addParameter("intent-id", "5298SFFLS735L");

// use Parameters to construct payload
let rsp = HttpClientV2.httpPost("https://www.externalconsent.org", headers, payload, "rt_profile", null, null, null, null, null, null, 5, true, null);
if (rsp.hasError()) {
    // handle error...
} else {
    // process response
}

// use string as payload
let rsp2 = HttpClientV2.httpPost("https://www.externalconsent.org", headers, "string payload", "rt_profile", null, null, null, null, null, null, 5, false, null);
if (rsp.hasError()) {
    // handle error...
} else {
    // process response
}

1. HttpClientV2

Return TypeMethodDescription
HttpResponsehttpGet(url, headers, httpsTrustStore, basicAuthUsername, basicAuthPassword, clientKeyStore, clientKeyAlias, protocol, throwExec, timeout, proxyServer)Send HTTP GET request to the specified URL.
HttpResponsehttpPut(url, headers, paramsOrPayload, httpsTrustStore, basicAuthUsername, basicAuthPassword, clientKeyStore, clientKeyAlias, protocol, throwExec, timeout, sendDataAsJson, proxyServer)Send HTTP PUT request to the specified URL.
HttpResponsehttpPost(url, headers, paramsOrPayload, httpsTrustStore, basicAuthUsername, basicAuthPassword, clientKeyStore, clientKeyAlias, protocol, throwExec, timeout, sendDataAsJson, proxyServer)Send HTTP POST request to the specified URL.
HttpResponsehttpPatch(url, headers, paramsOrPayload, httpsTrustStore, basicAuthUsername, basicAuthPassword, clientKeyStore, clientKeyAlias, protocol, throwExec, timeout, sendDataAsJson, proxyServer)Send HTTP PATCH request to the specified URL.
HttpResponsehttpDelete(url, headers, httpsTrustStore, basicAuthUsername, basicAuthPassword, clientKeyStore, clientKeyAlias, protocol, throwExec, timeout, proxyServer)Send HTTP DELETE request to the specified URL.

The following table describes the method of arguments:

NameData typeRequiredDescription
urlstringYesValid HTTP URL.
headersHeadersNoExtra HTTP headers.
paramsOrPayloadParameters OR stringNoParameters to be added to the HTTP request body. Alternatively, use raw string as the HTTP request body.
httpsTrustStorestringNoThe truststore to use. If an HTTPS connection is needed and this method is set to null, the default truststore that is specified in the provider configs is used.
basicAuthUsernamestringNoBasic authorization header username.
basicAuthPasswordstringNoBasic authorization header password.
clientKeyStorestringNoClient keystore. If null, client certificate authorization is disabled.
clientKeyAliasstringNoClient key alias. If null, client certificate authorization is disabled.
protocolstringNoNot used. This method is a mockup parameter for Verify Access compatibility.
throwExecBooleanNoNot used. This method is a mockup parameter for Verify Access compatibility.
timeoutintNoRequest timeout in seconds. A value of 0 results in a no connection timeout. If set to a value that is less than 0, the timeout is set to 5 seconds.
sendDataAsJsonBooleanNoSpecifies whether the parameters are in JSON. Defaults to false if not provided.
proxyServerstringNoThe full name of the proxy server to use. For example, https://proxy.com:443. Set to null if a proxy server is not needed.

2. HttpResponse

This object represents the HTTP response received.

Return TypeMethodDescriptionArguments
stringgetBody()Get the HTTP response body.
integergetCode()Get the HTTP response state code.
JS objectgetHeaders()Get the HTTP response headers.
string[]getHeaderKeys()Get the HTTP response header names.
string[]getHeaderValues(name)Get the HTTP response header value of the specified name.string
BooleanhasError()Checks whether any errors exist. This return type is called first to check whether an error exists when a new HttpResponse object is return from an HttpClient method.
stringgetError()Retrieve the error returned.

3. Headers

This class represents the HTTP header to be used in the HTTP request.

Return TypeMethodDescriptionArguments
Headers()Constructor of Headers class
addHeader(name, value)Add a headerstring, string
addHeader(name, values)Add a headerstring, string[]
string[]getHeader(name)Get the header values with the specified name. Returns null if no such header name.string
string[]getHeaderNames()Get all the header names. Returns null if no headers exist.
JS objectgetHeaders()Get all the headers

4. Parameters

This class stores the parameters to be added to the HTTP request body.

Return TypeMethodDescriptionArguments
Parameters()Constructor of Parameters class
addParameter(name, value)Add a parameterstring, string
addParameter(name, values)Add a parameterstring, string[]
string[]getParameter(name)Get the parameter values with the specified name. Returns null if no such parameter name.string
string[]getParameterNames()Get all the parameter names. Returns null if no parameters exist.
JS objectgetParameters()Get all the parameters

Note: If HttpClient method sendDataAsJson parameter is set to true, the parameters are treated as JSON data.
Otherwise, it is treated as form data. Ensure that the HTTP header Content-Type is set to the wanted value.