HTTP requests

Availability table

Controller availability

Module

Available

module.scripts

Supported feature

module.keycloak

Supported feature

http controller

This controller allows scripts to issue HTTP/HTTPS requests, with each request creating its own client, which is released at the end of the script.

HTTPS configuration :
  • CA certificate has to be in configuration in certs/external if not defined in default CA list of Ubuntu.

  • Support TLS1.3 and TLS1.2

http.doDelete(url: string, request?: HttpScriptRequest)

Send HTTP/S request using DELETE method.

Arguments:
  • url

  • request

Returns:

Response of the request of type HttpScriptResponse()

http.doGet(url: string, request?: HttpScriptRequest)

Send HTTP/S request using GET method.

Arguments:
  • url – The URL to reach can be an IP or a hostname. The schema must be included like http://example.com or https://example.com

  • request – The request builder who can be used to personalize request

Returns:

Response of the request of type HttpScriptResponse()

http.doPost(url: string, request?: HttpScriptRequest)

Send HTTP/S request using POST method.

Arguments:
  • url

  • request

Returns:

Response of the request of type HttpScriptResponse()

http.doPut(url: string, request?: HttpScriptRequest)

Send HTTP/S request using PUT method.

Arguments:
  • url

  • request

Returns:

Response of the request of type HttpScriptResponse()

http.doRequest(endpointId: string, parameters?: object, timeoutMs?: number)

Send HTTP/S request using an api service.

Arguments:
  • endpointId – The endpoint to use to the request

  • parameters – An object containing the key/value for each parameter

  • timeoutMs – The timeout in milliseconds to wait for a response

Returns:

Response of the request of type HttpScriptResponse()

http.getRequest()

This method is a helper to get an http object pre-defined with only data to fill.

Returns:

Return a HttpScriptRequest() to help to build a request.

HttpScriptRequest

class http.HttpScriptRequest()

A request builder that allows customization of a request by adding headers or modifying the timeout.

Default value are 1500 milliseconds for connection timeout Default value are 1500 milliseconds for socket timeout Default value are 1500 milliseconds for connection request timeout

HttpScriptRequest.addHeader(key: string, value: string)

Add a custom header for this request.

Arguments:
  • key

  • value

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.enablePreemptiveAuth()

Enable the preemptive authentication.

By default, the client wait for an Unauthorized (401) response before redoing the request with the authentication.

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.notFollowRedirects(notFollow: boolean)

Set whether the request follows redirect or not

Arguments:
  • notFollow – True mean that request won’t follow redirects.

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.setBody(body: <string | number[]>, contentType?: string)

Set the body of the request.

Arguments:
  • body

  • contentType

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.setConnectionRequestTimeout(timeoutMs: number)

Returns the connection lease request timeout used when requesting a connection. Default value is 1500 milliseconds

Arguments:
  • timeoutMs – The timeout value in milliseconds

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.setConnectionTimeout(timeoutMs: number)

Determines the timeout until a new connection is fully established. A timeout value of zero is interpreted as an infinite timeout.

Arguments:
  • timeoutMs – The timeout value in milliseconds, 0 value means infinite (not recommended at all)

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.setCredential(username: string, password: string)

Add username/password basic authentication to request.

Arguments:
  • username

  • password

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.setCredentialNtlm(username: string, password: string, workstation: string, domain: string)

Add NTLM authentication to request (mutually exclusive to any other credentials). NTLM authentication ignores the enablePreemptiveAuth configuration.

Arguments:
  • username

  • password

  • workstation

  • domain

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.setSocketTimeout(timeoutMs: number)

Determines the default socket timeout value for I/ O operations. Default is 1500 milliseconds

Arguments:
  • timeoutMs – The timeout value in milliseconds

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptRequest.setTimeout(timeoutMs: number)
Arguments:
  • timeoutMs –

    !! Deprecated !! Use dedicated method for each timeout instead

    Change the default timeout (1500 ms) for the fields: * Connection timeout * Socket timeout * Connection request timeout.

Returns:

Return a the request (HttpScriptRequest())filled with new attribute.

HttpScriptResponse

class http.HttpScriptResponse()

Represent a response of an HTTP/S request.

HttpScriptResponse.success

Indicate if the request was successful and the response code is in the 200-299 range.

The type of the field is boolean.

HttpScriptResponse.statusCode

Contain the status code of the response received.

The type of the field is number.

HttpScriptResponse.header

Contain the header of the response received.

The type of the field is string.

HttpScriptResponse.body

Contain the body of the response received.

The type of the field is string.

HttpScriptResponse.bodyBytes

Contain the body as bytes of the response received.

The type of the field is number[].

HttpScriptResponse.error

Contain the error of the response received.

The type of the field is string.

HttpScriptResponse.getBody()

Get body of the request response as string

Deprecated since version 2.1.0: Use HttpScriptResponse.body instead.

HttpScriptResponse.getBodyBytes()

Get body of the request response as byte array

Deprecated since version 2.1.0: Use HttpScriptResponse.bodyBytes instead.

HttpScriptResponse.getError()

Get error message of the request response.

Deprecated since version 2.1.0: Use HttpScriptResponse.error instead.

HttpScriptResponse.getHeader()

Get header of the HTTP/S response.

Deprecated since version 2.1.0: Use HttpScriptResponse.header instead.

HttpScriptResponse.getStatusCode()

Get HTTP/S status code responded by the server.

Deprecated since version 2.1.0: Use HttpScriptResponse.statusCode instead.

HttpScriptResponse.isSuccess()

Return true if the request is executed and the response code is in the 200-299 range

Deprecated since version 2.1.0: Use HttpScriptResponse.success instead.