class RouterList
implements IRouter
import { RouterList } from "https://deno.land/x/allo_routing@v1.0.1/routers/RouterList.ts";
Class RouterList
is main object. Contains all routers.
const router = new RouterList();
// ...
if (router.match(request)) {
const response = await router.serveResponse(request);
}
Constructors
new
RouterList(options?: RouterOptions)Methods
add(entry: string | URLPattern | RegExp, serveResponse: ServeResponseType): void
Adds new instance of router depending on entry
argument.
-
If is type of
string
. It will be used as mask forMaskRouter
. -
If is type of
URLPattern
. It will be used as pattern forPatternRouter
. -
If is type of
RegExp
. It will be used as regexp forRegExpRouter
.
Adds router to list. Router must implement IRouter
interface.
Router can be your custom class or instance of PatternRouter
, MaskRouter
or RegExpRouter
.
Btw, also you can add another instance of RouterList
too.
serveResponse(req: Request): Promise<Response>