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:
InvalidArgumentErrorif one of headers, method or query are missing.
| Param | Type | Description |
|---|---|---|
| headers | object | key-value object of headers |
| method | string | the HTTP method |
| query | object | key-value object of query parameters |
| [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 Request(req);
}request.get(field) ⇒ string
Get a request header (case-insensitive).
Kind: instance method of Request
| Param | Type |
|---|---|
| field | String |
request.is(...types) ⇒ boolean
Check if the content-type matches any of the given mime types.
Kind: instance method of Request
| Param | Type |
|---|---|
| ...types | Array.<string> |