@tshttp/status
🎰
Ultra typed, over documented, and neatly organised HTTP status enums, to use for a great developper experience.
Get started
yarn add @tshttp/status
npm install @tshttp/status
import { Status } from '@tshttp/status'
res.sendStatus(Status.Created)
Enums
Status
enum is composed of the following exported enums:
-
InformationStatus
for 1xx responses. -
SuccessStatus
for 2xx responses. -
RedirectionStatus
for 3xx responses. -
ErrorStatus
for 4xx and 5xx responses.
import { ErrorStatus } from '@tshttp/status'
import { HttpError } from '@tshttp/error'
throw HttpError(ErrorStatus.Forbidden)
These enums are actually object litterals with a const
assertion.`
Unions
When use as a type, each category is a union of corresponding status codes.
import { RedirectionStatus } from '@tshttp/status'
function redirect(status: RedirectionStatus, url: string) {
// ...
}
Reason phrase
A simple method called reason
transforms a status code into its human readable reason phrase :
import { reason, ErrorStatus } from '@tshttp/status'
reason(200) // "OK"
reason(301) // "Moved Permanently"
reason(404) // "Not Found"
reason(ErrorStatus.ImATeapot) // "I'm a teapot"