2.0.0 • Published 5 years ago
@tshttp/status v2.0.0
@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/statusimport { Status } from '@tshttp/status'
res.sendStatus(Status.Created)Enums
Status enum is composed of the following exported enums:
InformationStatusfor 1xx responses.SuccessStatusfor 2xx responses.RedirectionStatusfor 3xx responses.ErrorStatusfor 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"