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.20/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 deserializeBody to deserialize 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 an EndpointResponse from the provided body, which is serialized using the top-level serializeBody function. If the provided body is already a Response object, it will be returned with the headers provided on the init argument applied (if there are any). Extra serializers can be provided on the init argument to extend the data types that can be serialized.

Shorthand function for quickly serving a Handler. The default bind is localhost:80. This function is a one-liner:

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.

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

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.

Initializer options for an EndpointResponse.

A metadata object generated once for every request.

A ResponseInit applied to the Rpc response after resolving and packing the value to send to the client. The Headers object is always available. If the resolved value is a Response object already, the status and statusText will be ignored but the headers will still be applied.

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.

Type Aliases

The ServerInit options available when using the serve() shorthand function.