-
server
: Allows to optionally override the HTTP server instance to be used.Default:
undefined
. -
views
: An object to configuration render function.Default:
undefined
.-
dir
: A directory for the application's views. -
ext
: The default engine extension to use when omitted. -
engine
: Registers the given template engine.
-
-
cache
: An instance of the Cache class. -
settings
: An object that contains the application settings. -
views
: An object that contains the application's views configuration.
The pure-http
is an instance of the http.Server
class, so you can use all methods from the Node.js HTTP module. Additionally pure-http
provides methods of the Router class and some other methods.
Assigns setting name to value. You may store any value that you want, but certain names can be used to configure the behavior of the server.
Returns the value of name setting.
-
prefix
: Allow append the path before each route.Default:
undefined
.
Routes HTTP GET requests to the specified path with the specified handler functions.
Routes HTTP POST requests to the specified path with the specified handler functions.
Routes HTTP PUT requests to the specified path with the specified handler functions.
Routes HTTP PATCH requests to the specified path with the specified handler functions.
Routes HTTP DELETE requests to the specified path with the specified handler functions.
Routes HTTP HEAD requests to the specified path with the specified handler functions.
Routes HTTP OPTIONS requests to the specified path with the specified handler functions.
Routes HTTP TRACE requests to the specified path with the specified handler functions.
Routes HTTP CONNECT requests to the specified path with the specified handler functions.
This method accepts all of HTTP method of the request, such as GET, PUT, POST.
Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path.
The req object is an enhanced version of Node’s own request object and supports all built-in fields and methods.
Contains a reference to the instance of the
pure-http
that the request is being processed by. This allows you to access the methods and properties of thepure-http
instance. See Application.
Contains key-value pairs of data submitted in the request body. By default, it is
undefined
, and is populated when you use body-parsing middleware.
Contains the hostname derived from the Host HTTP header (included connection port).
Contains the hostname derived from the Host HTTP header.
This property is much like req.url; however, it retains the original request URL, allowing you to rewrite req.url freely for internal routing purposes.
An object containing parameter values parsed from the URL path.
For example if you have the route/user/:name
, then the "name" from the URL path wil be available asreq.params.name
. This object defaults to{}
.
Contains the path part of the request URL.
The connection port.
Contains the request protocol string: either http or (for TLS requests) https.
A Boolean property that is true if a TLS connection is established.
This property is an object containing a property for each query string parameter in the route. When query parser is set to disabled, it is an empty object
{}
, otherwise it is the result of the configured query parser.
Returns the specified HTTP request header field (case-insensitive match).
The res object is an enhanced version of Node’s own response object and supports all built-in fields and methods.
Sets headers on the response.
Sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using JSON.stringify().
The parameter can be any JSON type, including object, array, string, Boolean, number, or null, and you can also use it to convert other values to JSON.
Sends a JSON response with JSONP support. This method is identical to res.json(), except that it opts-in to JSONP callback support.
Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code . If not specified, status defaults to “302 “Found”.
Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code . If not specified, status defaults to “302 “Found”.
Renders a view and sends the rendered HTML string to the client. Optional parameters:
options
: An object whose properties define local variables for the view.callback
: A callback function. If provided, the method returns both the possible error and rendered string, but does not perform an automated response. When an error occurs, the method invokes onError(err, req, res) internally.
Sends the HTTP response.The body parameter can be a Buffer object, a String, an object, Boolean, or an Array.
Sets cookie name to value. The value parameter may be a string or object converted to JSON.
options
: An object to configuration theSet-Cookie
in header.
Clears the cookie specified by name. For details about the options object, see res.cookie().
Transfers the file at the given path. Sets the Content-Type response HTTP header field based on the filename’s extension.
Options:
headers
: The addition headers.
Sets the HTTP status for the response. It is a chainable alias of Node’s response.statusCode.
-
max
: The maximum number of items that can be stored in the cache.Default:
Infinity
. -
maxAge
: The maximum age of an item in the cache.Default:
0
. -
stale
: Allow stale items to be returned until they are removed from the cache.Default:
false
.
Reset the cache(s) and counter.
Check if the cache has the given key.
Get the assigned value for a given key. Will return
undefined
if the cache has evictedkey
or never contained it.
Persist an item to the cache by a given
key
name.
Removes item from cache.