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

x/frugal/dep/std/http.ts

A frugal web framework
Go to Latest
import * as frugal from "https://deno.land/x/frugal@0.3.0/dep/std/http.ts";

A collection of HTTP errors and utilities.

The export errors contains an individual class that extends HttpError which makes handling HTTP errors in a structured way.

The function createHttpError provides a way to create instances of errors in a factory pattern.

The function isHttpError is a type guard that will narrow a value to an HttpError instance.

Examples

import { errors, isHttpError } from "https://deno.land/std@0.224.0/http/http_errors.ts";

try {
  throw new errors.NotFound();
} catch (e) {
  if (isHttpError(e)) {
    const response = new Response(e.message, { status: e.status });
  } else {
    throw e;
  }
}
import { createHttpError } from "https://deno.land/std@0.224.0/http/http_errors.ts";
import { Status } from "https://deno.land/std@0.224.0/http/http_status.ts";

try {
  throw createHttpError(
    Status.BadRequest,
    "The request was bad.",
    { expose: false }
  );
} catch (e) {
  // handle errors
}

Classes

Provides an way to manage cookies in a request and response on the server as a single iterable collection.

The base class that all derivative HTTP extend, providing a status and an expose property.

Provides an way to manage cookies in a request and response on the server as a single iterable collection, as well as the ability to sign and verify cookies to prevent tampering.

Used to construct an HTTP server.

Enums

Standard HTTP status codes.

Variables

Symbol which is used in mergeHeaders to extract a [string | string][] from an instance to generate the final set of headers.

A map of HttpErrors that are unique instances for each HTTP error status code.

A record of all the status codes text.

Functions

Returns an array of media types accepted by the request, in order of preference. If there are no media types supplied in the request, then any media type selector will be returned.

Returns an array of content encodings accepted by the request, in order of preference. If there are no encoding supplied in the request, then ["*"] is returned, implying any encoding is accepted.

Returns an array of languages accepted by the request, in order of preference. If there are no languages supplied in the request, then ["*"] is returned, imply any language is accepted.

Create an instance of an HttpError based on the status code provided.

Set the cookie header with empty value in the headers to delete it

Parse cookies of a header

Parse set-cookies of a header

A type guard that determines if the status code is a client error.

A type guard that determines if the status code is an error.

A type guard that determines if the value is an HttpError or not.

A type guard that determines if the status code is informational.

A type guard that determines if the status code is a redirection.

A type guard that determines if the status code is a server error.

A type guard that determines if the status code is successful.

Allows merging of various sources of headers into a final set of headers which can be used in a Response.

Serves HTTP requests with the given handler.

Serves the files under the given directory root (opts.fsRoot).

Returns an HTTP Response with the requested file as the body.

Constructs a server, accepts incoming connections on the given listener, and handles requests on these connections with the given handler.

Serves HTTPS requests with the given handler.

Set the cookie header properly in the headers

Interfaces

Information about the connection a request arrived on.

Provides a iterable map interfaces for managing cookies server side.

An object which contains a headers property which has a value of an instance of Headers, like Request and Response.

An interface which describes the methods that SecureCookieMap uses to sign and verify cookies.

Interface for serveDir options.

Interface for serveFile options.

Additional serve options.

Options for running an HTTP server.

Type Aliases

An HTTP status that is a client error (4XX).

Types of data that can be signed cryptographically.

An HTTP status that is an error (4XX and 5XX).

Algorithm used to determine etag

A handler for HTTP requests. Consumes a request and connection information and returns a response.

An HTTP status that is a informational (1XX).

An HTTP status that is a redirect (3XX).

An HTTP status that is a server error (5XX).

An HTTP status that is a success (2XX).