Skip to content

Response

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

Kind: global class

new Response(headers, method, [body], ...otherOptions)

Create a new Response instance.

ParamTypeDescription
headersobjectkey-value object of headers
methodstringthe HTTP method
[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 Response(res);
}

response.get(field) ⇒ string | undefined

Get a response header.

Kind: instance method of Response

ParamTypeDescription
fieldstringthe field to access, case-insensitive

response.redirect(url)

Redirect response.

Kind: instance method of Response

ParamTypeDescription
urlstringthe url to redirect to

response.set(field, value)

Set a response header.

Kind: instance method of Response

ParamTypeDescription
fieldstringthe name of the header field, case-insensitive
valuestringthe new value of the header field