Appolo Route
Fast and simple http routing using radix tree
Installation:
npm install appolo-route --save
Usage:
let router = ; output = router; console // test2 console // working
Router
Options
useCache
- cache the find result by path, default :true
maxCacheSize
- The maximum size of the cache routes, default:1000
decodeUrlParams
- true to decodeURIComponent params value, default:false
Static route
let router = ; ;
Parametric route
let router = ;
Wildcard route
let router = ;
Regex route
same syntax as path-to-regexp
let router = ;
Api
find(method: Http.Methods, path: string): { params: Params, handler: any }
find route by path return object with params
and handler
if no params
found return empty object
let router = ; result = router; result // 123
get(path: string, handler: any): Router
register new Route handler using Http.Get Method
post(path: string, handler: any): Router
register new Route handler using Http.Post Method
put(path: string, handler: any): Router
register new Route handler using Http.Put Method
patch(path: string, handler: any): Router
register new Route handler using Http.Put Method
patch(path: string, handler: any): Router
register new Route handler using Http.Patch Method
delete(path: string, handler: any): Router
register new Route handler using Http.Delete Method
head(path: string, handler: any): Router
register new Route handler using Http.Delete Method
add(method:Http.Methods | Http.Methods[], path: string, handler: any): Router
register new Route handler. multi methods supported
let router = ;
remove(method:Http.Methods | Http.Methods[], path: string): Router
remove Route by path. multi methods supported
let router = ;
reset()
reset the router remove all routes
License
MIT