Skip to content

Request

Wrapper for webserver's request. Used to decouple this package from the webserver's request signature.

Kind: global class

new Request(headers, method, query, [body], ...otherOptions)

Creates a new request instance

Throws:

  • InvalidArgumentError if one of headers, method or query are missing.
ParamTypeDescription
headersobjectkey-value object of headers
methodstringthe HTTP method
queryobjectkey-value object of query parameters
[body]objectoptional key-value object of body parameters
...otherOptionsobjectany other properties that should be assigned to the request by your webserver

Example

js
function (req, res, next) {
  // most webservers follow a similar structure
  const response = new Request(req);
}

request.get(field) ⇒ string

Get a request header (case-insensitive).

Kind: instance method of Request

ParamType
fieldString

request.is(...types) ⇒ boolean

Check if the content-type matches any of the given mime types.

Kind: instance method of Request

ParamType
...typesArray.<string>