Toisu! router
The Toisu! router provides routing logic, using routing string like those of Express.
Usage
Internally the Toisu! router uses path-to-regexp.
When adding routes, the options parameter is passed along to path-to-regexp
. See that package for
what forms the strings can take (this should be familiar to express users).
const Toisu = ;const Router = ;const http = ; const app = ;const router = ; router; app; http;
The methods for a route are given a list of middleware each. If the router handles a request which
uses a method with no middlewares, then the router will respond with a 405 status code and an
Accept
header containing a list of methods which the router does have middlewares for.
Parameters distilled from a path are stored on the 'params'
field of the context Map. i.e.
{ const params = this; // etc.}
Routed middleware functions are in every other respect the same as unrouted middleware functions, and receive the same context.
API
Router
class const router = ;
router.route(path, handlers, [options])
The optional options
object is passed to path-to-regexp
, which is responsible for parsing the
path string. When a route and HTTP method match, parameters will be parsed from the string into an
object, which is appended to the context map as this.get('params')
{ const params = this; console; // { someData: <determined by req.url> }} router;
middleware = router.middleware
This can be consumed by a Toisu! app.use
call.
const app = ; app;