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.
| Param | Type | Description |
|---|---|---|
| headers | object | key-value object of headers |
| method | string | the HTTP method |
| [body] | object | optional key-value object of body parameters |
| ...otherOptions | object | any 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
| Param | Type | Description |
|---|---|---|
| field | string | the field to access, case-insensitive |
response.redirect(url)
Redirect response.
Kind: instance method of Response
| Param | Type | Description |
|---|---|---|
| url | string | the url to redirect to |
response.set(field, value)
Set a response header.
Kind: instance method of Response
| Param | Type | Description |
|---|---|---|
| field | string | the name of the header field, case-insensitive |
| value | string | the new value of the header field |