$k. HttpRequest

new HttpRequest(url, methodopt, queryDataopt)

Creates a new request

Parameters:
NameTypeAttributesDescription
urlstring

HTTP(S) URL

methodstring<optional>

Request method (GET, POST etc.). If undefined, GET is used

queryDataobject<optional>

Query data

Throws:

If the URL is invalid

A HTTP request

Type
$k.exception.InvalidValue

Extends

Methods

(static) current() → {$k.HttpRequest}

Returns the current incoming HttpRequest, or undefined if no request is active

Only supported in the following application environment(s): rest

Since
  • 5.4.0
Returns:
Type: 
$k.HttpRequest

(static) fromEncodedURL(url, methodopt, queryDataopt)

Creates a new request. THe URL must be already URL-encoded by the sender

Parameters:
NameTypeAttributesDescription
urlstring

HTTP(S) URL

methodstring<optional>

Request method (GET, POST etc.). If undefined, GET is used

queryDataobject<optional>

Query data

Version
  • Experimental feature, might be removed at any time
Since
  • 5.3.2
Throws:

If the URL is invalid

Type
$k.exception.InvalidValue

attach(attachment)

Attach a entity

Parameters:
NameTypeDescription
attachment$k.NetEntity
Inherited From
Throws:

If the entity is not a valid attachment

Type
$k.exception.TypeError

attachments() → {Array.<$k.NetEntity>}

Returns the attached entities

Returns:
Type: 
Array.<$k.NetEntity>

base64String() → {string}

Get the binay contents as base64-encoded string. Returns undefined if the contents is not binary

Returns:
Type: 
string

charset() → {string}

Returns the charset

Inherited From
Returns:
Type: 
string

contentDisposition() → {string}

Returns the content disposition

Returns:
Type: 
string

contentLength() → {number}

Returns the content length

Returns:
Type: 
number

contentType() → {string}

Returns the content type (only the media type part)

Returns:
Type: 
string

cookies() → {object}

Returns the cookies as an object. The name of a property is the cookie name

Returns:
Type: 
object

dataUrl() → {string}

Returns the entity bytes as a data URL, or undefined if the entity is not binary

Inherited From
Returns:
Type: 
string

debugString() → {string}

Prints the entity, except binary contents, for debugging purposes

Returns:
Type: 
string

filename() → {string}

Returns the filename part of the content disposition field

Inherited From
Returns:
Type: 
string

formData() → {object}

Get all form fields (multipart/form-data or application/x-www-form-urlencoded). The property names correspond to the field names. The property values are either strings (if the form is of type application/x-www-form-urlencoded) or NetEntities (multipart/form-data)

Inherited From
Returns:
Type: 
object

headerField(fieldName) → {string}

Get the value of the field of the request header. Returns undefined if the field does not exist

Parameters:
NameTypeDescription
fieldNamestring
Returns:

The field value

Type: 
string

headerFields() → {object}

Get all fields of the request header. Field names are always lower case

Returns:
Type: 
object

isBinary() → {boolean}

True if the entity has binary contents

Inherited From
Returns:
Type: 
boolean

method() → {string}

Returns the requests HTTP method

Returns:

HTTP method value of this request

Type: 
string

queryData() → {object}

Returns the query data of the request as an object. If the request method is GET, then this is equivalent to urlQueryData(). For other methods it returns application/x-www-form-urlencoded key/value pairs

Returns:
Type: 
object

removeHeaderField(fieldName)

Removes the field of the request heade

Parameters:
NameTypeDescription
fieldNamestring
Since
  • 5.0.3

setCharset(charset)

Set the charset

Parameters:
NameTypeDescription
charsetstring
Throws:

If the charset is unknown

Type
$k.exception.InvalidValue

setContentDisposition(contentDisposition)

Set the content disposition

Parameters:
NameTypeDescription
contentDispositionstring

setContentLength(length)

Set the content length

Parameters:
NameTypeDescription
lengthnumber

setContents(contents)

Set the contents of the entity. Also sets the content type and filename if known. The contents object can be a string, document ($k.TextDocument), a blob value ($k.Blob) or another NetEntity

Parameters:
NameTypeDescription
contents

Contents object

setContentType(mediaType, charsetopt)

Set the content type

Parameters:
NameTypeAttributesDescription
mediaTypestring

Media type of the contents

charsetstring<optional>

Charset of the contents

setFilename(filename)

Set the filename part of the content disposition field

Parameters:
NameTypeDescription
filenamestring

setFormData(formData)

Sets the url-encoded form data of the request

Parameters:
NameTypeDescription
formDataobject

setHeaderField(fieldName, fieldValue)

Set the value of the field of the request header

Parameters:
NameTypeDescription
fieldNamestring
fieldValue
Throws:

If the value does not match the type of the field

Type
$k.exception.TypeError

setQueryData(queryData)

Sets the query data of the URI. Each property is added as a query parameter (key=value). If the value of a property is an arry, then a key=value pair is added for each array element.

Parameters:
NameTypeDescription
queryDataobject

setText(text)

Set the text as the body

Parameters:
NameTypeDescription
textstring
Inherited From

setUrl(url)

Sets the URL

Parameters:
NameTypeDescription
urlstring
Throws:

If the URL is not valid

Type
$k.exception.InvalidValue

text(charsetopt) → {string}

Get the contents as string

Parameters:
NameTypeAttributesDescription
charsetstring<optional>

Charset of the characters. Required for binary entities. Optional for text entities.

Inherited From
Returns:
Type: 
string

url() → {string}

Returns the full URL

Returns:
Type: 
string

urlQueryData() → {object}

Returns the URL query data of the URI as an object. Each key=value pair is added as a property. If a key appears more than once, then the value is an array with all elements

Returns:
Type: 
object