RouterRequest

Provides AWS CloudFront request instance and methods.

Constructor

new RouterRequest(cfReqObj)

Parameters:
NameTypeDescription
cfReqObjCloudFrontRequest

CloudFront request object.

Methods

body() → {String}

Return the base64-encoded body data.

Returns:
Type: 
String

clientIp() → {String}

Return the HTTP client IP (remote address).

Returns:
Type: 
String

data() → {CloudFrontRequest}

Return CloudFront request object.

Returns:
Type: 
CloudFrontRequest

getHeaders() → {CloudFrontFunctionsHeaders}

Return the headers of the request.

Returns:
Type: 
CloudFrontFunctionsHeaders

Return value for given HTTP header name.

Parameters:
NameTypeDescription
nameString

HTTP header name.

Returns:
Type: 
String | undefined
Example
const value = req.header('Content-Type');
// text/html

is(mimeType) → {Boolean}

Check Accept matches the given value.

Parameters:
NameTypeDescription
mimeTypeString

MIME type value.

Returns:
Type: 
Boolean
Example
const value = req.is('text/html');
// true

method() → {String}

Return the HTTP method of the request.

Returns:
Type: 
String

param(name) → {String|Object|undefined}

Return the HTTP request parameters or name/value.

Parameters:
NameTypeDescription
nameString

Parameter name (optional).

Returns:
Type: 
String | Object | undefined
Example
const params = req.param();
// {name: 'value'}

const value = req.param('name');
// value

plugin(name, value) → {*|undefined}

Set/Get value passed down the application stack.

Parameters:
NameTypeDescription
nameString

Plugin name.

value*

Plugin value.

Returns:
Type: 
* | undefined
Example
req.plugin('name', 'value');

  ..

const value = req.plugin('name');
// value

queryString() → {String}

Return the serialized query parameters.

Returns:
Type: 
String

uri() → {String}

Return the relative path of the requested object.

Returns:
Type: 
String

(static) isJson(str) → {Boolean}

Check valid JSON string format.

Parameters:
NameTypeDescription
strString

JSON string.

Returns:
Type: 
Boolean

(static) isParams(str) → {Boolean}

Check valid HTTP request parameters.

Parameters:
NameTypeDescription
strString

Parameter name/value pairs.

Returns:
Type: 
Boolean

(static) parseBody(str) → {Object|undefined}

Convert base64-encoded request body to object.

Parameters:
NameTypeDescription
strString

base64 string.

Returns:
Type: 
Object | undefined

(static) parseParams(str) → {Object}

Convert serialized query string to object.

Parameters:
NameTypeDescription
strString

Parameter name/value pairs.

Returns:
Type: 
Object