Skip to main content
Module

x/cav/http.ts

A server framework for Deno
Go to Latest
import * as cav from "https://deno.land/x/cav@0.0.8/http.ts";

Variables

A special 404 HttpError that should be thrown whenever a handler is refusing to respond to a request due to the path not matching constraints. This is thrown by Rpcs when path matching fails. If a Stack catches this error, it will continue looking for matching routes.

Functions

Creates a cookie tied to the given request and response headers. The keys provided will be used for cookie signing; if no keys are provided, a random fallback key will be used. Keys need to be provided in an array, making key rotation easier.

Returns a parsed body from a given request after checking size constraints. Uses unpackBody to unpack the request body.

Generates or returns a previously generated RequestData for a given request. If this is the first time requestData is being called for the given request, the RequestData object is generated and returned. Every other time the request passes through this function, the same object generated on the first call is returned without further modification.

Creates a TypedResponse from the provided body, which undergoes packing via packBody. Extra packers can be provided using the "packers" option on the init argument. If a Response is passed in as the body, its body will be used without re-packing; headers and status/text will still be updated to match the provided init.

Shorthand function for quickly serving a Handler. This function is a one-liner:

Response factory for serving static assets. Asset resolution uses the provided ServeAssetOptions, the Request is only used for caching headers like ETag etc.

Creates a Server using the provided ServerInit. Note that there is no "onError" init option; errors that bubble up to the Server level are logged and a 500 Response is sent back to the client. You should handle errors as close as possible to where the error occurred, for example using the Rpc "onError" init option.

Constructs an asset Bundler for .ts and .tsx files. This uses Deno's runtime compiler API under the hood, which requires the --unstable flag. (https://deno.land/manual/typescript/runtime)

The server-side equivalent of the wrapWebSocket function in the client module. Returns a Response which should be returned by the handler for the socket upgrade to complete successfully.

Interfaces

Bundlers, when provided to the assets() function, will receive the on-disk path of a requested file. The bundler can then return null if it doesn't apply to the requested file, or it can return a Response to serve instead of using the standard library's fileServer to serve the file from disk. Bundlers are responsible for handling their own caching techniques.

Cav's cookie interface. This interface provides synchronous access to cookie values. The actual signing of signed cookies needs to be asynchronous, however. In order to compensate for this, once you are done accessing and modifying the cookie, you need to call the async "flush()" in order to sync cookie updates to the response headers that were provided when the cookie was initialized.

Limits what paths/domains a cookie should be deleted for.

Extends the Deno default cookie set options to include the "signed" flag.

A metadata object generated once for every request.

Options controlling how assets are found and served.

The standard http.Server type, but with a type parameter indicating the type of the handler that was passed in. The handler will usually be a Stack but could be any other type of Handler.

The standard http.ServerInit type with a type parameter indicating the type of the handler this server is serving. Additionally, the "onError" property has been omitted; errors in Cav should be handled at the Rpc level, as close as possible to where the error occurred. When an error bubbles up to the Server level, it will be logged and a 500 Response will be sent to the client.

A regular response that gets returned when a socket connection is established. The type parameter indicates the type of message the client can expect to receive from the server.

A Response, but with an unused type parameter indicating the type of the response body.

Initializer options for a TypedResponse. Adds packers to ResponseInit.