Deno Doc Components

Component Showcase


Markdown Summary

Some markdown with links and symbol links, like: Router

ModuleIndex

Index
archive
async

Provide help with asynchronous tasks like delays, debouncing, deferring, or pooling.

bytes

Provides helper functions to manipulate Uint8Array byte slices that are not included on the Uint8Array prototype.

collections

Functions for specific common tasks around collection types like Array and Record.

crypto

Extensions to the Web Crypto supporting additional encryption APIs.

datetime

Utilities for dealing with Date objects.

dotenv

Load environment variables from .env files.

encoding
examples
flags

Command line arguments parser based on minimist.

fmt
fs

Helpers for working with the filesystem.

hash

Deprecated. Use Web Crypto or std/crypto instead.

http

Provides user-friendly serve on top of Deno's native HTTP server and other utilities for creating HTTP servers and clients.

io

Utilities for working with Deno's readers, writers, and web streams.

log

Logging library with the support for terminal and file outputs. Also provides interfaces for building custom loggers.

media_types

Utility functions for media types (MIME types).

node
path

Utilities for working with OS-specific file paths.

permissions

Helpers for interacting with Deno's permissions system.

semver

The semantic version parser.

signal

Higher level API for dealing with OS signals.

streams

Utilities for working with the Streams API.

testing
textproto

A reader for dealing with low level text based protocols.

uuid

Generators and validators for UUIDs for versions v1, v4 and v5.

wasi
version.ts

ModuleIndexPanel

ssare
(default module)
N
etag
N
helpers
N
testing
c
Application
c
Context
c
Cookies
c
FlashServer
c
FormDataReader
c
HttpError
c
HttpRequest
c
HttpServerNative
c
MultiPartStream
c
NativeRequest
c
Request
c
Response
c
Router
c
ServerSentEvent
I
ApplicationOptions
I
BodyContentTypes
I
BodyOptions
I
BodyOptionsContentTypes
I
ByteRange
I
ContextSendOptions
I
CookiesGetOptions
I
CookiesSetDeleteOptions
I
FormDataBody
I
FormDataFile
I
FormDataReadOptions
I
ListenOptionsBase
I
ListenOptionsTls
I
Middleware
I
ProxyOptions
I
Route
I
RouterAllowedMethodsOptions
I
RouterContext
I
RouterMiddleware
I
RouterOptions
I
RouterParamMiddleware
I
SendOptions
I
ServerConstructor
I
ServerSentEventInit
I
ServerSentEventTarget
T
BodyBytes
T
BodyForm
T
BodyFormData
T
BodyJson
T
BodyReader
T
BodyStream
T
BodyText
T
BodyType
T
BodyUndefined
T
ErrorStatus
T
HTTPMethods
T
ListenOptions
T
RedirectStatus
T
RouteParams
T
State
v
httpErrors
v
REDIRECT_BACK
v
STATUS_TEXT
f
composeMiddleware
f
createHttpError
f
hasFlash
f
ifRange
f
isErrorStatus
f
isHttpError
f
isRedirectStatus
f
parseRange
f
proxy
f
send
E
Status
.ts
f
getQuery
rver_flash.ts
c
FlashServer
rver_native_request.ts
c
NativeRequest
I
NativeRequestOptions
rver_native.ts
c
HttpServer
T
Respond
rver_node.ts
Type.ts
f
isMediaType
k.ts
c
KeyStack
per.ts
f
format
f
parse
are.ts
I
Middleware
f
compose
rt.ts
c
FormDataReader
I
FormDataBody
I
FormDataFile
I
FormDataReadOptions
ims.ts
c
ErrorEvent
s
c
MultiPartStream
I
ByteRange
f
ifRange
f
parseRange
.ts
c
Request
e.ts
c
Response
T
ResponseBody
T
ResponseBodyFunction
v
REDIRECT_BACK
f
convertBodyToBodyInit
ts
c
Router
I
Route
I
RouterAllowedMethodsOptions
I
RouterContext
I
RouterMiddleware
I
RouterOptions
I
RouterParamMiddleware
T
RouteParams
I
SendOptions
f
send
sent_event.ts
c
ServerSentEvent
c
SSEStreamTarget
I
ServerSentEventInit
I
ServerSentEventTarget
I
ServerSentEventTargetOptions
red_clone.ts
T
StructuredClonable
f
cloneState
ps.ts
c
Buffer
c
StringReader
c
StringWriter
v
BufWriter
f
assert
f
assertEquals
f
assertInstanceOf
f
assertRejects
f
assertStrictEquals
f
assertThrows
f
unreachable
f
writeAllSync
.ts
I
MockContextOptions
v
mockContextState
f
createMockApp
f
createMockContext
f
createMockNext
.ts
I
HttpConn
I
Listener
I
RequestEvent
I
Server
I
ServerConstructor
I
ServerRequest
I
ServerRequestBody
I
UpgradeWebSocketOptions
T
Data
T
ErrorStatus
T
HTTPMethods
T
Key
T
RedirectStatus
T
UpgradeWebSocketFn
c
Uint8ArrayTransformStream
I
ReadableStreamFromReaderOptions
v
BODY_TYPES
v
DEFAULT_CHUNK_SIZE
f
assert
f
decodeComponent
f
encodeBase64Safe
f
encodeUrl
f
getBoundary
f
getRandomFilename
f
importKey
f
isAsyncIterable
f
isConn
f
isErrorStatus
f
isHtml
f
isListenTlsOptions
f
isNode
f
isReader
f
isRedirectStatus
f
isRouterContext
f
readableStreamFromAsyncIterable
f
readableStreamFromReader
f
resolvePath
f
sign
f
skipLWSPChar
f
stripEol

ModuleDoc

import * as oak from "https://deno.land/x/oak@v11.0.0/mod.ts";

A middleware framework for handling HTTP with Deno.

oak works well on both Deno CLI and Deno deploy, and is inspired by koa. It works well with both the Deno CLI and Deno Deploy.

Example server

A minimal router server which responds with content on /. With Deno CLI this will listen on port 8080 and on Deploy, this will simply serve requests received on the application.

import { Application, Router } from "https://deno.land/x/oak/mod.ts";

const router = new Router();
router.get("/", (ctx) => {
  ctx.response.body = `<!DOCTYPE html>
    <html>
      <head><title>Hello oak!</title><head>
      <body>
        <h1>Hello oak!</h1>
      </body>
    </html>
  `;
});

const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

app.listen({ port: 8080 });

Using Deno's flash server

Currently, Deno's flash server is not the default, even with the --unstable flag. In order to use the flash server, you need to provide the FlashServer to the Application constructor:

import { Application, FlashServer } from "https://deno.land/x/oak/mod.ts";

const app = new Application({ serverConstructor: FlashServer });

// register middleware

app.listen({ port: 8080 });

Note the currently Deno's flash server requires the --unstable flag. If it isn't present, the application will error on listening.

Namespaces

Classes

A class which registers middleware (via .use()) and then processes inbound requests against that middleware (via .listen()).

Provides context about the current request and response to middleware functions, and the current instance being processed is the first argument provided a Middleware function.

An interface which allows setting and accessing cookies related to both the current request and response. Each Context has a property .cookies which is an instance of this class.

A server abstraction which manages requests from Deno's flash server.

An interface which provides an interface to access the fields of a multipart/form-data body.

The base class that all derivative HTTP extend, providing a status and an expose property.

An abstraction which wraps a Request from Deno's flash server. The constructor takes a Deferred which it will resolve when the response is ready.

The oak abstraction of the Deno native HTTP server which is used internally for handling native HTTP requests. Generally users of oak do not need to worry about this class.

A class that takes a file (either a Deno.FsFile or Uint8Array) and bytes and streams the ranges as a multi-part encoded HTTP body.

An internal oak abstraction for handling a Deno native request. Most users of oak do not need to worry about this abstraction.

An interface which provides information about the current request. The instance related to the current request is available on the Context's .request property.

An interface to control what response will be sent when the middleware finishes processing the request.

An interface for registering middleware that will run when certain HTTP methods and paths are requested, as well as provides a way to parameterize parts of the requested path.

An event which contains information which will be sent to the remote connection and be made available in an EventSource as an event. A server creates new events and dispatches them on the target which will then be sent to a client.

Enums

Standard HTTP status codes.

Variables

A map of HttpErrors that are unique instances for each HTTP error status code.

A symbol that indicates to response.redirect() to attempt to redirect back to the request referrer. For example:

A record of all the status codes text.

Allows external parties to modify the context state.

Functions

Compose multiple middleware functions into a single middleware function.

Create an instance of an HttpError based on the status code provided.

Calculate an ETag value for an entity. If the entity is FileInfo, then the tag will default to a weak ETag. options.weak overrides any default behavior in generating the tag.

Create middleware that will attempt to decode the response.body into something that can be used to generate an ETag and add the ETag header to the response.

For a given Context, try to determine the response body entity that an ETag can be calculated from.

A helper function that takes the value from the If-Match header and an entity and returns true if the ETag for the entity matches the supplied value, otherwise false.

A helper function that takes the value from the If-No-Match header and an entity and returns false if the ETag for the entity matches the supplied value, otherwise false.

A function that determines if the current environment supports Deno flash.

Given a context, return the .request.url.searchParams as a Map of keys and values of the params.

Determine, by the value of an If-Range header, if a Range header should be applied to a request, returning true if it should or otherwise false.

Determines if a HTTP Status is an ErrorStatus (4XX or 5XX).

A type guard that determines if the value is an HttpError or not.

Determines if a HTTP Status is a RedirectStatus (3XX).

Middleware that provides a back-to-back proxy for requests.

Asynchronously fulfill a response with a file from the local file system.

Creates a mock of Application.

Create a mock of Context or RouterContext.

Creates a mock next() function which can be used when calling middleware.

Interfaces

Available options that are used when creating a new instance of Application.

Options which can be used when accessing the .body() of a request.

When setting the contentTypes property of BodyOptions, provide additional content types which can influence how the body is decoded. This is specifically designed to allow a server to support custom or specialized media types that are not part of the public database.

Just the part of Deno.FileInfo that is required to calculate an ETag, so partial or user generated file information can be passed.

When reading a body in full via .read() from a FormDataReader this is what is what the value is resolved, providing a split between any fields, and multi-part files that were provided.

A representation of a file that has been read from a form data body. Based on the FormDataReadOptions that were passed when reading will determine if files are written to disk or not and how they are written to disk. When written to disk, the extension of the file will be determined by the content type, with the .filename property containing the full path to the file.

Options which impact how the form data is decoded for a FormDataReader. All these options have sensible defaults for most applications, but can be modified for different use cases. Many of these options can have an impact on the stability of a server, especially if there is someone attempting a denial of service attack on your server, so be careful when changing the defaults.

Middleware are functions which are chained together to deal with requests.

The context passed router middleware.

Middleware that will be called by the router when handling a specific parameter, which the middleware will be called when a request matches the route parameter.

Options that can be set in a mock context.

Type Aliases

The tagged type for "bytes" bodies.

The tagged type for "form" bodies.

The tagged type for "form-data" bodies.

The tagged type for "json" bodies.

The tagged type for "reader" bodies.

The tagged type for "stream" bodies.

The tagged type for "text" bodies.

The type of the body, where:

The tagged type for "undefined" bodies.

A HTTP status that is an error (4XX and 5XX).

A HTTP status that is a redirect (3XX).

SymbolDoc

class Application
import { Application } from "https://deno.land/x/oak@v11.0.0/mod.ts";

An interface for registering middleware that will run when certain HTTP methods and paths are requested, as well as provides a way to parameterize parts of the requested path.

Basic example

import { Application, Router } from "https://deno.land/x/oak/mod.ts";

const router = new Router();
router.get("/", (ctx, next) => {
  // handle the GET endpoint here
});
router.all("/item/:item", (ctx, next) => {
  // called for all HTTP verbs/requests
  ctx.params.item; // contains the value of `:item` from the parsed URL
});

const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

app.listen({ port: 8080 });

Type Parameters

optional
RS extends State = Record<string, any>
[src]

Methods

all<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
name: string,
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register named middleware for the specified routes when the DELETE, GET, POST, or PUT method is requested.

all<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the DELETE, GET, POST, or PUT method is requested.

all<P extends RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the DELETE, GET, POST, or PUT method is requested with explicit path parameters.

all<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
allowedMethods(options?: RouterAllowedMethodsOptions): Middleware[src]

Middleware that handles requests for HTTP methods registered with the router. If none of the routes handle a method, then "not allowed" logic will be used. If a method is supported by some routes, but not the particular matched router, then "not implemented" will be returned.

The middleware will also automatically handle the OPTIONS method, responding with a 200 OK when the Allowed header sent to the allowed methods for a given route.

By default, a "not allowed" request will respond with a 405 Not Allowed and a "not implemented" will respond with a 501 Not Implemented. Setting the option .throw to true will cause the middleware to throw an HTTPError instead of setting the response status. The error can be overridden by providing a .notImplemented or .notAllowed method in the options, of which the value will be returned will be thrown instead of the HTTP error.

delete<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
name: string,
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register named middleware for the specified routes when the DELETE, method is requested.

delete<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the DELETE, method is requested.

delete<P extends RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the DELETE, method is requested with explicit path parameters.

delete<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
entries(): IterableIterator<[Route<string>, Route<string>]>[src]

Iterate over the routes currently added to the router. To be compatible with the iterable interfaces, both the key and value are set to the value of the route.

forEach(callback: (
value1: Route<string>,
value2: Route<string>,
router: this,
) => void
, thisArg?: any
): void
[src]

Iterate over the routes currently added to the router, calling the callback function for each value.

get<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
name: string,
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register named middleware for the specified routes when the GET, method is requested.

get<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the GET, method is requested.

get<P extends RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the GET, method is requested with explicit path parameters.

get<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
head<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
name: string,
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register named middleware for the specified routes when the HEAD, method is requested.

head<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the HEAD, method is requested.

head<P extends RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the HEAD, method is requested with explicit path parameters.

head<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
keys(): IterableIterator<Route<string>>[src]

Iterate over the routes currently added to the router. To be compatible with the iterable interfaces, the key is set to the value of the route.

options<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
name: string,
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register named middleware for the specified routes when the OPTIONS, method is requested.

options<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the OPTIONS, method is requested.

options<P extends RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the OPTIONS, method is requested with explicit path parameters.

options<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
param<R extends string, S extends State = RS>(param: keyof RouteParams<R>, middleware: RouterParamMiddleware<R, RouteParams<R>, S>): Router<S>[src]

Register param middleware, which will be called when the particular param is parsed from the route.

patch<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
name: string,
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register named middleware for the specified routes when the PATCH, method is requested.

patch<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the PATCH, method is requested.

patch<P extends RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the PATCH, method is requested with explicit path parameters.

patch<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
post<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
name: string,
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register named middleware for the specified routes when the POST, method is requested.

post<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the POST, method is requested.

post<P extends RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the POST, method is requested with explicit path parameters.

post<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
prefix(prefix: string): this[src]

Set the router prefix for this router.

put<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
name: string,
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register named middleware for the specified routes when the PUT method is requested.

put<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the PUT method is requested.

put<P extends RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware for the specified routes when the PUT method is requested with explicit path parameters.

put<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
nameOrPath: string,
pathOrMiddleware: string | RouterMiddleware<string, P, S>,
...middleware: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
redirect(
source: string,
destination: string | URL,
status?: RedirectStatus,
): this
[src]

Register a direction middleware, where when the source path is matched the router will redirect the request to the destination path. A status of 302 Found will be set by default.

The source and destination can be named routes.

routes(): Middleware[src]

Return middleware that will do all the route processing that the router has been configured to handle. Typical usage would be something like this:

import { Application, Router } from "https://deno.land/x/oak/mod.ts";

const app = new Application();
const router = new Router();

// register routes

app.use(router.routes());
app.use(router.allowedMethods());
await app.listen({ port: 80 });
url<P extends RouteParams<string> = RouteParams<string>>(
name: string,
params?: P,
options?: UrlOptions,
): string | undefined
[src]

Generate a URL pathname for a named route, interpolating the optional params provided. Also accepts an optional set of options.

use<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(middleware: RouterMiddleware<string, P, S>, ...middlewares: RouterMiddleware<string, P, S>[]): Router<S extends RS ? S : (S & RS)>[src]

Register middleware to be used on every matched route.

use<R extends string, P extends RouteParams<R> = RouteParams<R>, S extends State = RS>(
path: R,
middleware: RouterMiddleware<R, P, S>,
...middlewares: RouterMiddleware<R, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware to be used on every route that matches the supplied path.

use<P extends RouteParams<string>, S extends State = RS>(
path: string,
middleware: RouterMiddleware<string, P, S>,
...middlewares: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]

Register middleware to be used on every route that matches the supplied path with explicit path parameters.

use<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(
path: string[],
middleware: RouterMiddleware<string, P, S>,
...middlewares: RouterMiddleware<string, P, S>[],
): Router<S extends RS ? S : (S & RS)>
[src]
use<P extends RouteParams<string> = RouteParams<string>, S extends State = RS>(pathOrMiddleware: string | string[] | RouterMiddleware<string, P, S>, ...middleware: RouterMiddleware<string, P, S>[]): Router<S extends RS ? S : (S & RS)>[src]
values(): IterableIterator<Route<string, RouteParams<string>, RS>>[src]

Iterate over the routes currently added to the router.

[Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string)[src]
[Symbol.for("nodejs.util.inspect.custom")](
depth: number,
options: any,
inspect: (value: unknown, options?: unknown) => string,
)
[src]
[Symbol.iterator](): IterableIterator<Route<string, RouteParams<string>, RS>>[src]

Provide an iterator interface that iterates over the routes registered with the router.

Static Methods

url<R extends string>(
path: R,
params?: RouteParams<R>,
options?: UrlOptions,
): string
[src]

Generate a URL pathname based on the provided path, interpolating the optional params provided. Also accepts an optional set of options.

Tag

Deprecated
deprecated
Abstract
abstract
readonly
readonly
optional
Unstable
unstable

Usage

import * as example from "https://deno.land/x/example@v1.0.0/mod.ts";
import { MyClass } from "https://deno.land/x/example@v1.0.0/mod.ts";
import { namespace } from "https://deno.land/x/example@v1.0.0/mod.ts";

const { MyClass } = namespace;
import { type Interface } from "https://deno.land/x/example@v1.0.0/mod.ts";