Class: Request

Request

Request


new Request(props)

Do not initialize this class on your own. An instance of this class is provided to your handler as a parameter.

Parameters:
Name Type Description
props Object

Members


<readonly> app :App

App object, used to access application-wide settings.

Type:
See:

<readonly> headers :Object

HTTP request headers, following Node.js convention

Type:
  • Object
Example
req.headers
// => {
//   'accept': 'text/html',
//   'accept-language': 'en-US,en;q=0.8',
//   'referer': 'http://example.com/'
// }

<readonly> hostname :string

Hostname from Host (or X-Forwarded-Host, if present) HTTP header. This does not include the port.

Type:
  • string
Example
Host: "example.com:3000"
req.hostname // => "example.com"

<readonly> httpVersion :string

Version of the HTTP protocol used in the request

Type:
  • string
Example
HTTP/1.1
req.httpVersion // => "1.1"

<readonly> httpVersionMajor :number

Major version of the HTTP protocol used in the request

Type:
  • number
Example
// HTTP/1.0
req.httpVersionMajor // => 1

<readonly> httpVersionMinor :number

Minor version of the HTTP protocol used in the request

Type:
  • number
Example
// HTTP/1.0
req.httpVersionMinor // => 0

<readonly> ip :string

The IP address of the remote host that sent the HTTP request. If X-Forwarded-For request header is present, this returns the first IP address in the header.

Type:
  • string
Example
req.ip // => 123.4.56.78

<readonly> ips :Array.<string>

List of IP addresses in the X-Forwarded-For request header

Type:
  • Array.<string>
Example
req.ips // => ["123.4.56.78", "201.11.22.33"]

<readonly> meta :Object

Extra metadata from the FaaS provider

Type:
  • Object
Example
req.meta
// => {
//   'provider': 'amazon',
//   'requestContext': {
//     'accountId': '123456789000',
//     'resourceId': 'abcd12',
//    ...

<readonly> method :string

HTTP method of the request, for example, GET, POST, PUT, DELETE, and so on.

Type:
  • string
Example
req.method // => "GET"

<readonly> params :Object

Object containing route parameters

Type:
  • Object
Example
// Route: /tasks/{taskSlug}comments/{commentId}
// GET /tasks/my-awesome-task/comments/2
req.params
// => {
//   'taskSlug': 'my-awesome-task',
//   'commentId': '2'
// }

<readonly> path :string

Current path

Type:
  • string
See:
Example
req.path  // => "/tasks/123"
req.routeString // => "/tasks/{id}"

<readonly> port :number

Port from Host (or X-Forwarded-Port, if present) HTTP header. If port is missing in the header, it returns 80 or 443 depending on the protocol used.

Type:
  • number
Example
req.port // => 443

<readonly> protocol :string

Protocol used for the HTTP request, for example, https or http.

Type:
  • string
Example
req.protocol // => "https"

<readonly> query :Object

Object containing query string parameters

Type:
  • Object
Example
// GET /search?q=hello+world&order=desc
req.query
// => {
//   'search': 'hello world'
//   'order': 'desc'
// }
// GET /list?item[id]=123&item[type]=open&order=desc
req.query
// => {
//   'item': {
//     'id': '123',
//     'type': 'open'
//   },
//   'order': 'desc'
// }

<readonly> rawBody :string

Raw, unparsed request body

Type:
  • string
Example
req.rawBody // => "foo=bar&baz=qux"

<readonly> route :Object

Current route. It is wrapped in an object for compatibility reasons.

Type:
  • Object
See:
Example
req.route // => { path: "/tasks/{id}" }

<readonly> routeString :string

Current route.

Type:
  • string
See:
Example
req.routeString // => "/tasks/{id}"

<readonly> secure :boolean

Whether the protocol used is https

Type:
  • boolean

<readonly> stage :Object

Object containing stage variables

Type:
  • Object
Example
req.stage
// => {
//   'GITHUB_USERNAME': 'petejkim',
//   'SECRET_TOKEN': 'Ui9to8Uv1Zm6Su9jHDqw7wSRd8WI'
// }

<readonly> url :string

HTTP request URL string. This does not include the protocol, hostname, and the port.

Type:
  • string
See:
Example
// GET /search?q=pete
req.url // => "/search?q=pete"

<readonly> xhr :boolean

Whether the HTTP request is an AJAX request. This returns true when X-Request-With: XMLHttpRequest header is present.

Type:
  • boolean

Methods


get(field)

Returns the value of the HTTP request header by a given field. The match is not case-sensitive.

Parameters:
Name Type Description
field string

Header field name

Returns:

value of the header

Type
string