Class: Request
Represents an HTTP request.
Methods
setEntity | Sets the provided |
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 |
hasHeader | Checks whether the requested header key exists in the header map. |
getHeader | Returns the value of the specified header. |
getHeaders | Gets all the header values to which the specified header key maps to. |
setHeader | Sets the specified header to the request. |
addHeader | Adds the specified header to the request. |
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 |
setContentType | Sets the |
getContentType | Gets the type of the payload of the request (i.e: the |
getJsonPayload | Extracts |
getXmlPayload | Extracts |
getTextPayload | Extracts |
getByteStream | Gets the request payload as a stream of byte[], except in the case of multiparts. |
getBinaryPayload | Gets the request payload as a |
getFormParams | Gets the form parameters from the HTTP request as a |
getBodyParts | Extracts body parts from the request. |
setJsonPayload | Sets a |
setXmlPayload | Sets an |
setTextPayload | Sets a |
setBinaryPayload | Sets a |
setBodyParts | Set multiparts as the payload. |
setFileAsPayload | Sets the content of the specified file as the entity body of the request. |
setByteStream | Sets a |
setPayload | Sets the request payload. |
addCookies | Adds cookies to the request. |
getCookies | Gets cookies from the request. |
Fields
- rawPath string(default "")
- method string(default "")
- httpVersion string(default "")
- userAgent string(default "")
- extraPathInfo string(default "")
- cacheControl RequestCacheControl?(default ())
- mutualSslHandshake MutualSslHandshake?(default ())
Resource path of the request URL
The HTTP request method
The HTTP version supported by the client
The user-agent. This value is used when setting the user-agent
header
The part of the URL, which matched to '*' if the request is dispatched to a wildcard resource
The cache-control directives for the request. This needs to be explicitly initialized if intending on utilizing HTTP caching.
A record providing mutual ssl handshake results.
getQueryParamValue
Gets the query param value associated with the given key.
Parameters
- key string
Represents the query param key
Return Type
(string?)The query param value associated with the given key as a string. If multiple param values are
present, then the first value is returned. ()
is returned if no key is found.
getEntity
function 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
getHeader
function getHeader(string headerName) returns string | HeaderNotFoundError
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 | HeaderNotFoundError)The first header value for the specified header name or the HeaderNotFoundError
if the header is not
found.
getHeaders
function getHeaders(string headerName) returns string[ ] | HeaderNotFoundError
Gets all the header values to which the specified header key maps to.
Parameters
- headerName string
The header name
Return Type
(string[ ] | HeaderNotFoundError)The header values the specified header key maps to or the HeaderNotFoundError
if the header is not
found.
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. Panic if an illegal header is passed.
removeAllHeaders
function removeAllHeaders()
Removes all the headers from the request.
getJsonPayload
function getJsonPayload() returns json | ClientError
Extracts json
payload from the request. If the content type is not JSON, an http:ClientError
is returned.
getXmlPayload
function getXmlPayload() returns xml | ClientError
Extracts xml
payload from the request. If the content type is not XML, an http:ClientError
is returned.
getTextPayload
function getTextPayload() returns string | ClientError
Extracts text
payload from the request. If the content type is not of type text, an http:ClientError
is returned.
getByteStream
function getByteStream(int arraySize) returns stream<byte[ ], Error?> | ClientError
Gets the request payload as a stream of byte[], except in the case of multiparts. To retrieve multiparts, use
Request.getBodyParts()
.
Parameters
- arraySize int (default 8192)
A defaultable parameter to state the size of the byte array. Default size is 8KB
Return Type
(stream<byte[ ], Error?> | ClientError)A byte stream from which the message payload can be read or http:ClientError
in case of errors
getBinaryPayload
function 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
function getFormParams() returns map<string> | ClientError
Gets the form parameters from the HTTP request as a map
when content type is application/x-www-form-urlencoded.
getBodyParts
function 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)The body parts as an array of entities or else an http:ClientError
if there were any errors
constructing the body parts from the request
setJsonPayload
function setJsonPayload(json payload, string? contentType)
Sets a json
as the payload. If the content-type header is not set then this method set content-type
headers with the default content-type, which is application/json
. Any existing content-type can be
overridden by passing the content-type as an optional parameter.
Parameters
- payload json
The json
payload
- contentType string? (default ())
The content type of the payload. This is an optional parameter.
The application/json
is the default value
setXmlPayload
Sets an xml
as the payload. If the content-type header is not set then this method set content-type
headers with the default content-type, which is application/xml
. Any existing content-type can be
overridden by passing the content-type as an optional parameter.
setTextPayload
Sets a string
as the payload. If the content-type header is not set then this method set
content-type headers with the default content-type, which is text/plain
. Any
existing content-type can be overridden by passing the content-type as an optional parameter.
setBinaryPayload
function setBinaryPayload(byte[ ] payload, string? contentType)
Sets a byte[]
as the payload. If the content-type header is not set then this method set content-type
headers with the default content-type, which is application/octet-stream
. Any existing content-type
can be overridden by passing the content-type as an optional parameter.
Parameters
- payload byte[ ]
The byte[]
payload
- contentType string? (default ())
The content type of the payload. This is an optional parameter.
The application/octet-stream
is the default value
setBodyParts
Set multiparts as the payload. If the content-type header is not set then this method
set content-type headers with the default content-type, which is multipart/form-data
.
Any existing content-type can be overridden by passing the content-type as an optional parameter.
setFileAsPayload
Sets the content of the specified file as the entity body of the request. If the content-type header
is not set then this method set content-type headers with the default content-type, which is
application/octet-stream
. Any existing content-type can be overridden by passing the content-type
as an optional parameter.
setByteStream
Sets a Stream
as the payload. If the content-type header is not set then this method set content-type
headers with the default content-type, which is application/octet-stream
. Any existing content-type can
be overridden by passing the content-type as an optional parameter.
setPayload
function setPayload(string | xml | json | byte[ ] | Entity[ ] | stream<byte[ ], Error?> payload, string? contentType)
Sets the request payload. This method overrides any existing content-type by passing the content-type as an optional parameter. If the content type parameter is not provided then the default value derived from the payload will be used as content-type only when there are no existing content-type header.
Parameters
- contentType string? (default ())
Content-type to be used with the payload. This is an optional parameter