Skip to main content
Module

x/allo_routing/mod.ts>RouterList

🦕 Routing solution for Deno
Go to Latest
class RouterList
implements IRouter
import { RouterList } from "https://deno.land/x/allo_routing@v1.0.0-beta3/mod.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 for MaskRouter.

  • If is type of URLPattern. It will be used as pattern for PatternRouter.

  • If is type of RegExp. It will be used as regexp for RegExpRouter.

addRouter(router: IRouter): void

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.

match(req: Request): Promise<boolean>