Object - http : Request

Represents an HTTP request.

Methods

setEntity

Sets the provided Entity to the request.

getQueryParams

Gets the query parameters of the request as a map consisting of a string array.

getQueryParamValue

Gets the query param value associated with the given key.

getQueryParamValues

Gets all the query param values associated with the given key.

getMatrixParams

Gets the matrix parameters of the request.

getEntity

Gets the Entity associated with the request.

hasHeader

Checks whether the requested header key exists in the header map.

getHeader

Returns the value of the specified header. If the specified header key maps to multiple values, the first of these values is returned.

getHeaders

Gets all the header values to which the specified header key maps to.

setHeader

Sets the specified header to the request. If a mapping already exists for the specified header key, the existing header value is replaced with the specified header value.

addHeader

Adds the specified header to the request. Existing header values are not replaced.

removeHeader

Removes the specified header from the request.

removeAllHeaders

Removes all the headers from the request.

getHeaderNames

Gets all the names of the headers of the request.

expects100Continue

Checks whether the client expects a 100-continue response.

setContentType

Sets the content-type header to the request.

getContentType

Gets the type of the payload of the request (i.e: the content-type header value).

getJsonPayload

Extracts json payload from the request. If the content type is not JSON, an http:ClientError is returned.

getXmlPayload

Extracts xml payload from the request. If the content type is not XML, an http:ClientError is returned.

getTextPayload

Extracts text payload from the request. If the content type is not of type text, an http:ClientError is returned.

getByteChannel

Gets the request payload as a ByteChannel except in the case of multiparts. To retrieve multiparts, use getBodyParts().

getBinaryPayload

Gets the request payload as a byte[].

getFormParams

Gets the form parameters from the HTTP request as a map when content type is application/x-www-form-urlencoded.

getBodyParts

Extracts body parts from the request. If the content type is not a composite media type, an error is returned.

setJsonPayload

Sets a json as the payload.

setXmlPayload

Sets an xml as the payload.

setTextPayload

Sets a string as the payload.

setBinaryPayload

Sets a byte[] as the payload.

setBodyParts

Set multiparts as the payload.

setFileAsPayload

Sets the content of the specified file as the entity body of the request.

setByteChannel

Sets a ByteChannel as the payload.

setPayload

Sets the request payload. Note that any string value is set as text/plain. To send a JSON-compatible string, set the content-type header to application/json or use the setJsonPayload method instead.

Fields

  • rawPath string
  • Resource path of the request URL

  • method string
  • The HTTP request method

  • httpVersion string
  • The HTTP version supported by the client

  • userAgent string
  • The user-agent. This value is used when setting the user-agent header

  • extraPathInfo string
  • Additional information associated with the URL provided by the client

  • cacheControl RequestCacheControl? ()
  • The cache-control directives for the request. This needs to be explicitly initialized if intending on utilizing HTTP caching.

  • mutualSslHandshake MutualSslHandshake? ()
  • A record providing mutual ssl handshake results.

setEntity

Sets the provided Entity to the request.

Parameters

  • e Entity
  • The Entity to be set to the request

getQueryParams

()

returns map

Gets the query parameters of the request as a map consisting of a string array.

  • Return Type

    (map)
  • String array map of the query params

getQueryParamValue

(string key)

returns string

Gets the query param value associated with the given key.

Parameters

  • key string
  • Represents the query param key

  • Return Type

    (string)
  • Returns the query param value associated with the given key as a string. If multiple param values are present, then the first value is returned. Nil is returned if no key is found.

getQueryParamValues

(string key)

returns string

Gets all the query param values associated with the given key.

Parameters

  • key string
  • Represents the query param key

  • Return Type

    (string)
  • Returns all the query param values associated with the given key as a string[]. Nil is returned if no key is found.

getMatrixParams

(string path)

returns map

Gets the matrix parameters of the request.

Parameters

  • path string
  • Path to the location of matrix parameters

  • Return Type

    (map)
  • A map of matrix parameters which can be found for the given path

getEntity

()

returns Entity | ClientError

Gets the Entity associated with the request.

  • Return Type

    (Entity | ClientError)
  • The Entity of the request. An http:ClientError is returned, if entity construction fails

hasHeader

(string headerName)

returns boolean

Checks whether the requested header key exists in the header map.

Parameters

  • headerName string
  • The header name

  • Return Type

    (boolean)
  • Returns true if the specified header key exists

getHeader

(string headerName)

returns string

Returns the value of the specified header. If the specified header key maps to multiple values, the first of these values is returned.

Parameters

  • headerName string
  • The header name

  • Return Type

    (string)
  • The first header value for the specified header name. An exception is thrown if no header is found. Use hasHeader() beforehand to check the existence of header.

getHeaders

(string headerName)

returns string

Gets all the header values to which the specified header key maps to.

Parameters

  • headerName string
  • The header name

  • Return Type

    (string)
  • The header values the specified header key maps to. An exception is thrown if no header is found. Use hasHeader() beforehand to check the existence of header.

setHeader

Sets the specified header to the request. If a mapping already exists for the specified header key, the existing header value is replaced with the specified header value.

Parameters

  • headerName string
  • The header name

  • headerValue string
  • The header value

addHeader

Adds the specified header to the request. Existing header values are not replaced.

Parameters

  • headerName string
  • The header name

  • headerValue string
  • The header value

removeHeader

Removes the specified header from the request.

Parameters

  • key string
  • The header name

removeAllHeaders

Removes all the headers from the request.

getHeaderNames

()

returns string

Gets all the names of the headers of the request.

  • Return Type

    (string)
  • An array of all the header names

expects100Continue

()

returns boolean

Checks whether the client expects a 100-continue response.

  • Return Type

    (boolean)
  • Returns true if the client expects a 100-continue response

setContentType

(string contentType)

returns error

Sets the content-type header to the request.

Parameters

  • contentType string
  • Content type value to be set as the content-type header

  • Return Type

    (error)
  • Nil if successful, error in case of invalid content-type

getContentType

()

returns string

Gets the type of the payload of the request (i.e: the content-type header value).

  • Return Type

    (string)
  • Returns the content-type header value as a string

getJsonPayload

()

returns json | ClientError

Extracts json payload from the request. If the content type is not JSON, an http:ClientError is returned.

  • Return Type

    (json | ClientError)
  • The json payload or http:ClientError in case of errors

getXmlPayload

()

returns xml | ClientError

Extracts xml payload from the request. If the content type is not XML, an http:ClientError is returned.

  • Return Type

    (xml | ClientError)
  • The xml payload or http:ClientError in case of errors

getTextPayload

()

returns string | ClientError

Extracts text payload from the request. If the content type is not of type text, an http:ClientError is returned.

  • Return Type

    (string | ClientError)
  • The text payload or http:ClientError in case of errors

getByteChannel

()

returns ReadableByteChannel | ClientError

Gets the request payload as a ByteChannel except in the case of multiparts. To retrieve multiparts, use getBodyParts().

getBinaryPayload

()

returns byte | ClientError

Gets the request payload as a byte[].

  • Return Type

    (byte | ClientError)
  • The byte[] representation of the message payload or http:ClientError in case of errors

getFormParams

()

returns map | ClientError

Gets the form parameters from the HTTP request as a map when content type is application/x-www-form-urlencoded.

  • Return Type

    (map | ClientError)
  • The map of form params or http:ClientError in case of errors

getBodyParts

()

returns Entity[] | ClientError

Extracts body parts from the request. If the content type is not a composite media type, an error is returned.

  • Return Type

    (Entity[] | ClientError)
  • Returns the body parts as an array of entities or an http:ClientError if there were any errors in constructing the body parts from the request

setJsonPayload

Sets a json as the payload.

Parameters

  • payload json
  • The json payload

  • contentType string (default application/json)
  • The content type of the payload. Set this to override the default content-type header value for json

setXmlPayload

Sets an xml as the payload.

Parameters

  • payload xml
  • The xml payload

  • contentType string (default application/xml)
  • The content type of the payload. Set this to override the default content-type header value for xml

setTextPayload

Sets a string as the payload.

Parameters

  • payload string
  • The string payload

  • contentType string (default text/plain)
  • The content type of the payload. Set this to override the default content-type header value for string

setBinaryPayload

Sets a byte[] as the payload.

Parameters

  • payload byte
  • The byte[] payload

  • contentType string (default application/octet-stream)
  • The content type of the payload. Set this to override the default content-type header value for byte[]

setBodyParts

Set multiparts as the payload.

Parameters

  • bodyParts Entity[]
  • The entities which make up the message body

  • contentType string (default multipart/form-data)
  • The content type of the top level message. Set this to override the default content-type header value

setFileAsPayload

Sets the content of the specified file as the entity body of the request.

Parameters

  • filePath string
  • Path to the file to be set as the payload

  • contentType string (default application/octet-stream)
  • The content type of the specified file. Set this to override the default content-type header value

setByteChannel

Sets a ByteChannel as the payload.

Parameters

  • contentType string (default application/octet-stream)
  • The content type of the payload. Set this to override the default content-type header value

setPayload

Sets the request payload. Note that any string value is set as text/plain. To send a JSON-compatible string, set the content-type header to application/json or use the setJsonPayload method instead.

Parameters

  • payload string | xml | json | byte | ReadableByteChannel | Entity[]
  • Payload can be of type string, xml, json, byte[], ByteChannel, or Entity[] (i.e., a set of body parts).