Skip to main content
Module

x/dactyl/mod.ts>Router

Web framework for Deno, built on top of Oak 🦇
Latest
class Router
extends OakRouter
import { Router } from "https://deno.land/x/dactyl@v0.1.0-alpha/mod.ts";

Router subclass - abstraction on top of Router class from Oak.

exposes methods Router.register() and router.middleware() to Application class for bootstrapping Oak application

Constructors

new
Router()

Properties

private
bootstrapMsg: string

Methods

private
appendToBootstrapMsg(msg: string): string

Helper that updates the internal bootstrap message. Used on application start to display on screen success.

private
buildRouteArgumentsFromMeta(
args: RouteArgument[],
methodName: string,
params: any,
body: any,
query: any,
headers: any,
context: RouterContext,
): any[]

Helper method for constructing controller action arguments from metadata on the controller.

private
handleUnknownException(error: any, res: any): void

Helper method for handling non-standard exceptions raised at runtime. This could be caused by an unhandled promise rejection, or a custom error thrown either internally or from an external module.

Dactyl will send a 500 error to the end user.

private
retrieveFromContext(context: RouterContext): Promise<{ params: any; headers: any; query: any; body: any; }>

Helper function for deconstructing Oaks RouterContext context object. Retreives context.params, context.request.headers, context.request.url.searchParams, and context.request.body() and maps them appropriately

private
sendNoData(res: any): void

Helper method called when controller action returns no json, and RouterContext context.response.body contains no body

getBootstrapMsg(): string

Returns message to be displayed when application starts

middleware(): Middleware

middleware getter for the internal router. To be used in Application bootstrap where appropriate, E.g.

// From Oak
const app: Application = new Application();
// From Dactyl
const router: Router = new Router();
// ... register controllers ...
app.use(router.middleware());
// routes now mapped to oak
register(controller: Newable<any>): void

Register function consumed by Application, takes controller class definition and strips it's metadata. From this metadata, the register function appropriately configures super() oak router. An instance of the provided controller class definition is created, and the controller's actions are mapped to routes, E.g.

import { DinosaurController } from "./example/DinosaurController.ts";

const router: Router = new Router();
router.register(DinosaurController);
// router superclass now configured to use DinosaurController's actions

Static Properties

private
LOGO_ASCII: string