Skip to main content
Module

x/duck_web_framework/router.ts>Router

A Deno express-like HTTP server
Latest
class Router
import { Router } from "https://deno.land/x/duck_web_framework@0.1.1/router.ts";

Router stores route handlers and middlewares. It can have a base URL specified, which will be prepended to every route. Every middleware will only work on requests that point to URL that starts with that base.

Constructors

new
Router(base?: string)

Properties

private
_base: string
private
_middlewares: Middleware[]
readonly
middlewares

Methods

private
route(
path: string,
method: HTTPMethods,
)
all(path: string, ...middlewares: MiddlewareFunction[])

Uses specified middleware(s) on given path, matching all HTTP methods

delete(path: string, ...middlewares: MiddlewareFunction[])
get(path: string, ...middlewares: MiddlewareFunction[])

Uses specified middleware(s) on given path, if request method is GET. All other methods match HTTP methods according to their name (post matches POST, delete matches DELETE etc.)

head(path: string, ...middlewares: MiddlewareFunction[])
patch(path: string, ...middlewares: MiddlewareFunction[])
post(path: string, ...middlewares: MiddlewareFunction[])
put(path: string, ...middlewares: MiddlewareFunction[])

Pushes given middleware or merges another router's middlewares with this router's middlewares