Skip to main content

@std/http@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)

Contains the STATUS_CODE object which contains standard HTTP status codes and provides several type guards for handling status codes with type safety.

Examples

Example 1

import {
  STATUS_CODE,
  STATUS_TEXT,
} from "@std/http/status";

console.log(STATUS_CODE.NotFound); // Returns 404
console.log(STATUS_TEXT[STATUS_CODE.NotFound]); // Returns "Not Found"

Example 2

import { isErrorStatus } from "@std/http/status";

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

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

Functions

f
isClientErrorStatus(status: number): status is ClientErrorStatus

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

f
isErrorStatus(status: number): status is ErrorStatus

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

f
isInformationalStatus(status: number): status is InformationalStatus

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

f
isRedirectStatus(status: number): status is RedirectStatus

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

f
isServerErrorStatus(status: number): status is ServerErrorStatus

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

f
isStatus(status: number): status is StatusCode

Returns whether the provided number is a valid HTTP status code.

f
isSuccessfulStatus(status: number): status is SuccessfulStatus

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

Type Aliases

T
ClientErrorStatus =
STATUS_CODE.BadRequest
| STATUS_CODE.Unauthorized
| STATUS_CODE.PaymentRequired
| STATUS_CODE.Forbidden
| STATUS_CODE.NotFound
| STATUS_CODE.MethodNotAllowed
| STATUS_CODE.NotAcceptable
| STATUS_CODE.ProxyAuthRequired
| STATUS_CODE.RequestTimeout
| STATUS_CODE.Conflict
| STATUS_CODE.Gone
| STATUS_CODE.LengthRequired
| STATUS_CODE.PreconditionFailed
| STATUS_CODE.ContentTooLarge
| STATUS_CODE.URITooLong
| STATUS_CODE.UnsupportedMediaType
| STATUS_CODE.RangeNotSatisfiable
| STATUS_CODE.ExpectationFailed
| STATUS_CODE.Teapot
| STATUS_CODE.MisdirectedRequest
| STATUS_CODE.UnprocessableEntity
| STATUS_CODE.Locked
| STATUS_CODE.FailedDependency
| STATUS_CODE.UpgradeRequired
| STATUS_CODE.PreconditionRequired
| STATUS_CODE.TooManyRequests
| STATUS_CODE.RequestHeaderFieldsTooLarge
| STATUS_CODE.UnavailableForLegalReasons

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

T
ErrorStatus = ClientErrorStatus | ServerErrorStatus

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

T
InformationalStatus =
STATUS_CODE.Continue
| STATUS_CODE.SwitchingProtocols
| STATUS_CODE.Processing
| STATUS_CODE.EarlyHints

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

T
RedirectStatus =
STATUS_CODE.MultipleChoices
| STATUS_CODE.MovedPermanently
| STATUS_CODE.Found
| STATUS_CODE.SeeOther
| STATUS_CODE.UseProxy
| STATUS_CODE.TemporaryRedirect
| STATUS_CODE.PermanentRedirect

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

T
ServerErrorStatus =
STATUS_CODE.InternalServerError
| STATUS_CODE.NotImplemented
| STATUS_CODE.BadGateway
| STATUS_CODE.ServiceUnavailable
| STATUS_CODE.GatewayTimeout
| STATUS_CODE.HTTPVersionNotSupported
| STATUS_CODE.VariantAlsoNegotiates
| STATUS_CODE.InsufficientStorage
| STATUS_CODE.LoopDetected
| STATUS_CODE.NotExtended
| STATUS_CODE.NetworkAuthenticationRequired

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

T
StatusCode = STATUS_CODE[keyof STATUS_CODE]

An HTTP status code.

T
StatusText = STATUS_TEXT[keyof STATUS_TEXT]

An HTTP status text.

T
SuccessfulStatus =
STATUS_CODE.OK
| STATUS_CODE.Created
| STATUS_CODE.Accepted
| STATUS_CODE.NonAuthoritativeInfo
| STATUS_CODE.NoContent
| STATUS_CODE.ResetContent
| STATUS_CODE.PartialContent
| STATUS_CODE.MultiStatus
| STATUS_CODE.AlreadyReported
| STATUS_CODE.IMUsed

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

Variables

v
STATUS_CODE: { Continue: number; SwitchingProtocols: number; Processing: number; EarlyHints: number; OK: number; Created: number; Accepted: number; NonAuthoritativeInfo: number; NoContent: number; ResetContent: number; PartialContent: number; MultiStatus: number; AlreadyReported: number; IMUsed: number; MultipleChoices: number; MovedPermanently: number; Found: number; SeeOther: number; NotModified: number; UseProxy: number; TemporaryRedirect: number; PermanentRedirect: number; BadRequest: number; Unauthorized: number; PaymentRequired: number; Forbidden: number; NotFound: number; MethodNotAllowed: number; NotAcceptable: number; ProxyAuthRequired: number; RequestTimeout: number; Conflict: number; Gone: number; LengthRequired: number; PreconditionFailed: number; ContentTooLarge: number; URITooLong: number; UnsupportedMediaType: number; RangeNotSatisfiable: number; ExpectationFailed: number; Teapot: number; MisdirectedRequest: number; UnprocessableEntity: number; Locked: number; FailedDependency: number; TooEarly: number; UpgradeRequired: number; PreconditionRequired: number; TooManyRequests: number; RequestHeaderFieldsTooLarge: number; UnavailableForLegalReasons: number; InternalServerError: number; NotImplemented: number; BadGateway: number; ServiceUnavailable: number; GatewayTimeout: number; HTTPVersionNotSupported: number; VariantAlsoNegotiates: number; InsufficientStorage: number; LoopDetected: number; NotExtended: number; NetworkAuthenticationRequired: number; }

Contains the STATUS_CODE object which contains standard HTTP status codes and provides several type guards for handling status codes with type safety.

v
STATUS_TEXT: { [[STATUS_CODE.Accepted]]: string; [[STATUS_CODE.AlreadyReported]]: string; [[STATUS_CODE.BadGateway]]: string; [[STATUS_CODE.BadRequest]]: string; [[STATUS_CODE.Conflict]]: string; [[STATUS_CODE.Continue]]: string; [[STATUS_CODE.Created]]: string; [[STATUS_CODE.EarlyHints]]: string; [[STATUS_CODE.ExpectationFailed]]: string; [[STATUS_CODE.FailedDependency]]: string; [[STATUS_CODE.Forbidden]]: string; [[STATUS_CODE.Found]]: string; [[STATUS_CODE.GatewayTimeout]]: string; [[STATUS_CODE.Gone]]: string; [[STATUS_CODE.HTTPVersionNotSupported]]: string; [[STATUS_CODE.IMUsed]]: string; [[STATUS_CODE.InsufficientStorage]]: string; [[STATUS_CODE.InternalServerError]]: string; [[STATUS_CODE.LengthRequired]]: string; [[STATUS_CODE.Locked]]: string; [[STATUS_CODE.LoopDetected]]: string; [[STATUS_CODE.MethodNotAllowed]]: string; [[STATUS_CODE.MisdirectedRequest]]: string; [[STATUS_CODE.MovedPermanently]]: string; [[STATUS_CODE.MultiStatus]]: string; [[STATUS_CODE.MultipleChoices]]: string; [[STATUS_CODE.NetworkAuthenticationRequired]]: string; [[STATUS_CODE.NoContent]]: string; [[STATUS_CODE.NonAuthoritativeInfo]]: string; [[STATUS_CODE.NotAcceptable]]: string; [[STATUS_CODE.NotExtended]]: string; [[STATUS_CODE.NotFound]]: string; [[STATUS_CODE.NotImplemented]]: string; [[STATUS_CODE.NotModified]]: string; [[STATUS_CODE.OK]]: string; [[STATUS_CODE.PartialContent]]: string; [[STATUS_CODE.PaymentRequired]]: string; [[STATUS_CODE.PermanentRedirect]]: string; [[STATUS_CODE.PreconditionFailed]]: string; [[STATUS_CODE.PreconditionRequired]]: string; [[STATUS_CODE.Processing]]: string; [[STATUS_CODE.ProxyAuthRequired]]: string; [[STATUS_CODE.ContentTooLarge]]: string; [[STATUS_CODE.RequestHeaderFieldsTooLarge]]: string; [[STATUS_CODE.RequestTimeout]]: string; [[STATUS_CODE.URITooLong]]: string; [[STATUS_CODE.RangeNotSatisfiable]]: string; [[STATUS_CODE.ResetContent]]: string; [[STATUS_CODE.SeeOther]]: string; [[STATUS_CODE.ServiceUnavailable]]: string; [[STATUS_CODE.SwitchingProtocols]]: string; [[STATUS_CODE.Teapot]]: string; [[STATUS_CODE.TemporaryRedirect]]: string; [[STATUS_CODE.TooEarly]]: string; [[STATUS_CODE.TooManyRequests]]: string; [[STATUS_CODE.Unauthorized]]: string; [[STATUS_CODE.UnavailableForLegalReasons]]: string; [[STATUS_CODE.UnprocessableEntity]]: string; [[STATUS_CODE.UnsupportedMediaType]]: string; [[STATUS_CODE.UpgradeRequired]]: string; [[STATUS_CODE.UseProxy]]: string; [[STATUS_CODE.VariantAlsoNegotiates]]: string; }

A record of all the status codes text.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/http

Import symbol

import * as mod from "@std/http/status";
or

Import directly with a jsr specifier

import * as mod from "jsr:@std/http/status";