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

x/reno/reno/mod.ts

A thin, testable routing library designed to sit on top of Deno's standard HTTP module
Latest
import * as reno from "https://deno.land/x/reno@v2.0.105/reno/mod.ts";

Classes

An error that's thrown by Reno when a route for a particular request's path cannot be found in the router's route map. You won't need to instantiate and throw this directly, but it's exported to support instanceof checks in error handling logic:

Functions

A unit testing utility to assert that actual and expected are deeply equal. The benefit of using this function over assertEquals directly is that it will convert ReadableStream bodies to strings, making them human-readable and thus helping to debug assertion failures:

Creates a RouteMap, a Map that holds route handling functions and keys them by the path by which the router will make them accessible:

Creates a Reno router for the given routes, which can then be invoked as an async function when Deno's HTTP server receives a request:

Takes mappings of HTTP methods and route handler functions, and returns a higher-order route handler that will forward requests to the correct handler by their method. Any requests whose method does not have an associated handler will result in a HTTP 405:

A response creator function for building JSON responses, that: defaults the Content-Type header to "application/json"; and serialises the JSON body to a string that's then encoded as a Uint8Array

A response creator function for building stream responses. This one currently doesn't do anything special, but it at least saves the effort of having to create response objects manually, and in the future may contain some sort of enhancing behaviour

Assigns the provided cookies to the underlying Response instance, which are then sent to the requestor via multiple Set-Cookie headers:

A higher-order function that takes a route handler function and returns another route handler that parses form data bodies before invoking the inner handler. The data is parsed internally by creating a URLSearchParams instance, which is then passed to the inner handler via the body prop of the first argument:

A higher-order function that takes a route handler function and returns another route handler that parses JSON bodies before invoking the inner handler:

Type Aliases

The standard request type used througout Reno, which is passed to user-defined route handler functions. Mostly identical to std/http's ServerRequest, except the inclusion of Reno-specific props for ease of use.

The standard response type returned by route handler functions. Essentially the same as std/http's Response, but also exposes cookies as an array of [string, string] tuples.

A ProcessedRequest with a body type reflecting a URLSearchParams instance.

A union of all possible HTTP methods, as uppercase strings, since deno/std doesn't provide one.

A ProcessedRequest that allows the body type to be specified via the sole type parameter. Defaults to an empty object.

An AugmentedRequest with an additional property containing the body after it has been parsed or processed, typically by one of the built-in middlewares. For example, the withJsonBody() middleware will deserialise the raw body with JSON.parse() and assign the result to the parsedBody property before forwarding the ProcessedRequest to the wrapped route handler.

A user-defined route handler for a particular route.

A standard ECMAScript Map that holds route handler functions that are keyed by either RegExps or strings.

The router function returned by createRouter that is intended to be invoked when a HTTP server receives a request.

A function that takes a routes map and returns an invocable router function.