Skip to main content
Module

x/acorn/router.ts

A focused RESTful server framework for Deno 🌰🦕
Latest
import * as acorn from "https://deno.land/x/acorn@0.5.1/router.ts";

The router for acorn, which is the foundational part of the framework.

Examples

Example 1

import { Router } from "jsr:@oak/acorn/router";

const router = new Router();

router.get("/", () => ({ hello: "world" }));

const BOOKS = {
  "1": { title: "The Hound of the Baskervilles" },
  "2": { title: "It" },
};

router.get("/books/:id", (ctx) => BOOKS[ctx.params.id]);

router.listen({ port: 3000 });

Classes

A DOM like event emitted by the router when a request has been handled.

A DOM like event that is emitted from the router when any request did not match any routes.

A router which is specifically geared for handling RESTful type of requests and providing a straight forward API to respond to them.

Error events from the router will be of this type, which provides additional context about the error and provides a way to override the default behaviors of the router.

The event class that is emitted when the router starts listening.

An event that is raised when the router is processing an event. If the event's response property is set after the event completes its dispatch, then the value will be used to send the response, otherwise the router will attempt to match a route.

Interfaces

The interface for route handlers, which are provided via a context argument. The route handler is expected to return a RouteResponse or undefined if it cannot handle the request, which will typically result in a 404 being returned to the client.

Options that can be specified when adding a route to the router.

An interface of route options which also includes the handler, intended to make it easy to provide a single object to register a route.

Context to be provided when invoking the .handle() method on the router.

Options which can be used when creating a new router.

The init for a RouterRequestEvent.

The interface too status handlers, which are registered on the Router via the .on() method and intended for being notified of certain state changes related to routing requests.

Type Aliases

The type alias to help infer what the route parameters are for a route based on the route string.

Valid return values from a route handler.

A Status code or a shorthand StatusRange string.

A string that represents a range of HTTP response Status codes: