HTTP Constants
This package contains various HTTP constants: http status codes and texts,
HTTP header names and HTTP methods, and a few related utility function.
Install
# NPM
npm i @poppanator/http-constants
# Yarn
yarn add @poppanator/http-constants
Usage
The following symbols are exported
status
Contains all possible HTTP status codes
import { status } from '@poppanator/http-constants'
status.Continue
status.Ok
status.Created
status.NotFound
status.InternalServerError
statusText
Contains all possible status texts
import { statusText } from '@poppanator/http-constants'
statusText.Continue
statusText.Ok
statusText.Created
statusText.NotFound
statusText.InternalServerError
tuple
Contains all status codes and texts as tuples where the first index is
the status code and the second index the status text.
import { tuple } from '@poppanator/http-constants'
const [code, text] = tuple.Unauthorized
const [code, text] = tuple.NotFound
Contains all standardizes HTTP header names (and a few non- but
defacto-standard ones).
import { header } from '@poppanator/http-constants'
header.AcceptEncoding
header.IfModifiedSince
header.AccessControlAllowMethods
method
Contains all standardized HTTP method names.
import { method, type Method } from '@poppanator/http-constants'
method.Post
method.Options
interface MyHttpInterface {
method: Method
}
const http: MyHttpInterface = {
method: 'FAKE',
}
const http: MyHttpInterface = {
method: 'POST',
}
Utility functions
Some utility functions are exported from the root of the package
import {
isInformational,
isSuccess,
isRedirect,
isClientError,
isServerError,
isHttpStatus,
getStatusText,
} from '@poppanator/http-constants'
isInformational(100)
isInformational(102)
isInformational(201)
isInformational(403)
isSuccess(200)
isSuccess(202)
isSuccess(100)
isSuccess(302)
isRedirect(301)
isRedirect(307)
isRedirect(200)
isRedirect(500)
isClientError(404)
isClientError(406)
isClientError(500)
isClientError(302)
isServerError(500)
isServerError(503)
isServerError(200)
isServerError(308)
isHttpStatus(201)
isHttpStatus(404)
isHttpStatus(503)
isHttpStatus(261)
isHttpStatus(210)
isHttpStatus(444)
getStatusText(100)
getStatusText(201)
getStatusText(304)
getStatusText(405)
getStatusText(500)