std/http/mod.ts

Deno standard library
Go to Latest
import * as mod from "https://deno.land/std@0.147.0/http/mod.ts";

Contains the enum Status which enumerates standard HTTP status codes and provides several type guards for handling status codes with type safety.

Examples

import {
  Status,
  STATUS_TEXT,
} from "https://deno.land/std@0.147.0/http/http_status.ts";

console.log(Status.NotFound); //=> 404
console.log(STATUS_TEXT[Status.NotFound]); //=> "Not Found"
import { isErrorStatus } from "https://deno.land/std@0.147.0/http/http_status.ts";

const res = await fetch("https://example.com/");

if (isErrorStatus(res.status)) {
  // error handling here...
}

Classes

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

Used to construct an HTTP server.

Enums

Standard HTTP status codes.

Variables

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

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.

f
listenAndServe
deprecated

Serves HTTP requests with the given handler.

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.

Additional serve options.

Options for running an HTTP server.

Type Aliases

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

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

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).