webapp

ModuleServer-Side

Web app router and utilities

Documentation

webappRouter
RouterrequestpathPathhandlerRequestCallbackmethodnullStringoptionsnullRouteOptionsgetpathPathhandlerRequestCallbackoptionsnullRouteOptionspostpathPathhandlerRequestCallbackoptionsnullRouteOptionsputpathPathhandlerRequestCallbackoptionsnullRouteOptionsdeletepathPathhandlerRequestCallbackoptionsnullRouteOptionsrouterequestRequestresponseResponsefunctiontrueundefinedurlnameStringargsnullObjectoptionsnullUrlOptionsstringpathsobject

Web application router and utilities. get, post, put, and delete are convenience methods for associating URL endpoints (via request) with a request handler and options. route will forward a request to the associated endpoint using the request object's method and path, returning any function returned from its handler, or true if otherwise matched to an endpoint.

If an endpoint is named and has a string path, url will return its url given its name and args. If a value in args corresponds to a path segment, it is substituted there; otherwise, it is appended as a query string argument unless undefined (and null values append only their key to the query string).

paths is an object mapping names to path strings for use by url and populated internally by request. It is accessible for serialization here, and can be passed in with url's options in different contexts.

PathstringRegExpstringRegExp...

String paths should be used where possible to enable url construction. Parameters within string paths are alphabetic identifiers starting with : (e.g. /hello/:name) and match path substrings with no / characters. The full input path must match the endpoint path to trigger its handler.

RouteOptionsstringstring...namestringstring...bodyFormatnullstringbodyMaxLengthnullnumber

As a string, RouteOptions sets the name of the endpoint. If path is an array, name should be an array of strings of the same size. If specified, bodyFormat ('utf8', 'url', or 'json') populates request.body by parsing the incoming request before handler is invoked.

UrlOptionspathsobject