Skip to main content
Module

x/http_router/mod.ts>Router

HTTP request router for standard Request and Response
Latest
import { Router } from "https://deno.land/x/http_router@3.0.0-beta.7/mod.ts";

HTTP router builder.

Examples

Example 1

import { Router } from "https://deno.land/x/http_router@$VERSION/mod.ts";
const router = new Router().get("/api/greet", () => Response.json({ hello: "world" }));

const response = await router.handler(new Request("http://localhost"));

Type Parameters

optional
GlobalContext = unknown

Properties

readonly
handler: Handler<GlobalContext>

Get composed handler.

readonly
routes: readonly Route<GlobalContext>[]

Registered all routes.

Methods

all<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL.

all<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL.

all(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL.

connect<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of CONNECT.

connect<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of CONNECT.

connect(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of CONNECT.

delete<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of DELETE.

delete<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of DELETE.

delete(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of DELETE.

get<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of GET.

get<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of GET.

get(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of GET.

head<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of HEAD.

head<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of HEAD.

head(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of HEAD.

options<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of OPTIONS.

options<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of OPTIONS.

options(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of OPTIONS.

patch<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of PATCH.

patch<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of PATCH.

patch(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of PATCH.

post<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of POST.

post<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of POST.

post(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of POST.

put<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of PUT.

put<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of PUT.

put(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of PUT.

route(base: string, ...routers: readonly RouterLike<GlobalContext>[]): this

Use the different routers.

route(...routers: readonly RouterLike<GlobalContext>[]): this
trace<Path extends string>(pattern: Readonly<URLPatternInit> & { readonly pathname?: Path; }, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP method of TRACE.

trace<Path extends string>(path: Path, ...middleware: readonly Middleware<GlobalContext & RouteContext<ParseUrlParams<Path>>>[]): this

Register handler that matched on HTTP request URL and HTTP request method of TRACE.

trace(...middleware: readonly Middleware<GlobalContext & RouteContext>[]): this

Register handler that matched on HTTP request URL and HTTP request method of TRACE.