Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rutt/mod.ts

🛣️ A tiny and fast http request router designed for use with deno and deno deploy
Latest
import * as rutt from "https://deno.land/x/rutt@0.3.0/mod.ts";

Rutt is a tiny http router designed for use with deno and deno deploy. It is written in about 300 lines of code and is fast enough, using an extended type of the web-standard URLPattern to provide fast and easy route matching.

Examples

Example 1

import { router } from "https://deno.land/x/rutt/mod.ts";

await Deno.serve(
  router({
    "/": (_req) => new Response("Hello world!", { status: 200 }),
  }),
).finished;

Variables

All known HTTP methods.

Functions

Builds an InternalRoutes array from a Routes record.

The default error handler for the router. By default it responds with null body and a status of 500 along with console.error logging the caught error.

The default other handler for the router. By default it responds with null body and a status of 404.

The default unknown method handler for the router. By default it responds with null body, a status of 405 and the Accept header set to all known methods.

A simple and tiny router for deno. This function provides a way of constructing a HTTP request handler for the provided routes and any provided RouterOptions.

Interfaces

The internal route object contains either a RegExp pattern or URLPattern which is matched against the incoming request URL. If a match is found for both the pattern and method the associated MatchHandler is called.

Additional options for the router function.

A record of route paths and MatchHandlers which are called when a match is found along with it's values.

Type Aliases

A handler type for anytime the MatchHandler or other parameter handler fails

A handler for HTTP requests. Consumes a request and HandlerContext and returns an optionally async response.

Provides arbitrary context to Handler functions along with ConnInfo | connection information.

An array of internal route objects which the routes record is mapped into. This array is used internally in the router function and can even be passed directly to it if you do not wish to use the routes record or want more fine grained control over matches, for example by using a RegExp pattern instead of a URLPattern.

A known HTTP method.

A handler type for a router path match which gets passed the matched values

A handler type for anytime a method is received that is not defined