import * as mod from "https://deno.land/std@0.145.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@$STD_VERSION/http/http_status.ts";
console.log(Status.NotFound); //=> 404
console.log(STATUS_TEXT[Status.NotFound]); //=> "Not Found"
import { isErrorStatus } from "https://deno.land/std@$STD_VERSION/http/http_status.ts";
const res = await fetch("https://example.com/");
if (isErrorStatus(res.status)) {
// error handling here...
}
Variables
STATUS_TEXT | A record of all the status codes text. |
Functions
deleteCookie | Set the cookie header with empty value in the headers to delete it |
getCookies | Parse cookies of a header |
isClientErrorStatus | A type guard that determines if the status code is a client error. |
isErrorStatus | A type guard that determines if the status code is an error. |
isInformationalStatus | A type guard that determines if the status code is informational. |
isRedirectStatus | A type guard that determines if the status code is a redirection. |
isServerErrorStatus | A type guard that determines if the status code is a server error. |
isSuccessfulStatus | A type guard that determines if the status code is successful. |
listenAndServe 👎 deprecated | |
listenAndServeTls 👎 deprecated | |
serve | Serves HTTP requests with the given handler. |
serveListener | Constructs a server, accepts incoming connections on the given listener, and handles requests on these connections with the given handler. |
serveTls | Serves HTTPS requests with the given handler. |
setCookie | Set the cookie header properly in the headers |
Interfaces
ConnInfo | Information about the connection a request arrived on. |
Cookie | |
ServeInit | Additional serve options. |
ServerInit | Options for running an HTTP server. |
ServeTlsInit |
Type Aliases
ClientErrorStatus | An HTTP status that is a client error (4XX). |
ErrorStatus | An HTTP status that is an error (4XX and 5XX). |
Handler | A handler for HTTP requests. Consumes a request and connection information and returns a response. |
InformationalStatus | An HTTP status that is a informational (1XX). |
RedirectStatus | An HTTP status that is a redirect (3XX). |
ServerErrorStatus | An HTTP status that is a server error (5XX). |
SuccessfulStatus | An HTTP status that is a success (2XX). |