Class: Router
Generic wrapper for an express
router. Associates endpoint templates in the format METHOD /path/:param
with handler functions.
Hierarchy
- Router
Index
Constructors
Properties
Methods
Constructors
constructor
+ new Router(transform
: Function): Router
Defined in lib/control/Router.ts:13
Parameters:
Name | Type | Default |
---|---|---|
transform |
Function | null |
Returns: Router
Properties
router
• router: Function
Defined in lib/control/Router.ts:11
An express
router
transform
• transform: Function
Defined in lib/control/Router.ts:13
Methods
declare
▸ declare(method
: string, route
: string, callback
: Function | Router): void
Defined in lib/control/Router.ts:27
Associates a callback function with an HTTP method and route.
Parameters:
Name | Type | Description |
---|---|---|
method |
string | An HTTP method |
route |
string | A route in the express syntax (e.g /user/:id ) |
callback |
Function | Router | A callback function |
Returns: void
options
▸ options(path
: string): Promise‹Array‹string› | State›
Defined in lib/control/Router.ts:78
(async) Returns a promise resolving to either: 1) an array containing all HTTP methods available at the given path
, or 2) a NOT_FOUND
error.
Parameters:
Name | Type | Description |
---|---|---|
path |
string | A path string. |
Returns: Promise‹Array‹string› | State›
request
▸ request(method
: string, path
: string, ...args
: Array‹any›): Promise‹any›
Defined in lib/control/Router.ts:59
(async) Attempts to execute a request using the constructed router.
Parameters:
Name | Type | Description |
---|---|---|
method |
string | An HTTP method. |
path |
string | A path string. |
...args |
Array‹any› | An object containing the arguments to be passed to the callback method, if one is found. |
Returns: Promise‹any›
A promise that evaluates to the result of invoking the callback function associated with the provided method and path, or a NOT_FOUND
State
if no matching endpoint exists.
retrieve
▸ retrieve(method
: string, path
: string): Promise‹any›
Defined in lib/control/Router.ts:43
Finds the function or Router associated with a given HTTP method and route. Returns undefined if none exist.
Parameters:
Name | Type | Description |
---|---|---|
method |
string | An HTTP method |
path |
string | - |
Returns: Promise‹any›