1.0.3 • Published 4 years ago

@empari/http-status-codes v1.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

HTTP Status Codes

Constants enumerating the HTTP status codes. Based on the Java Apache HttpStatus API.

All status codes defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), RFC2518 (WebDAV), RFC6585 (Additional HTTP Status Codes), and RFC7538 (Permanent Redirect) are supported.

Completely library agnostic. No dependencies.

Installation

npm install @empari/http-status-codes --save

or

yarn add @empari/http-status-codes

Usage (express 4.x)

const { HttpStatus } = require('@empari/http-status-codes')
const httpStatus = new HttpStatus()

response.status(HttpStatus.OK).send('ok')

response.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
  error: httpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)
})

response.status(httpStatus.getStatusCode('Server Error')).send({
  error: 'Server Error'
})

Codes

ConstantCodeStatus Text
ACCEPTED202Accepted
BAD_GATEWAY502Bad Gateway
BAD_REQUEST400Bad Request
CONFLICT409Conflict
CONTINUE100Continue
CREATED201Created
EXPECTATION_FAILED417Expectation Failed
FAILED_DEPENDENCY424Failed Dependency
FORBIDDEN403Forbidden
GATEWAY_TIMEOUT504Gateway Timeout
GONE410Gone
HTTP_VERSION_NOT_SUPPORTED505HTTP Version Not Supported
IM_A_TEAPOT418I'm a teapot
INSUFFICIENT_SPACE_ON_RESOURCE419Insufficient Space on Resource
INSUFFICIENT_STORAGE507Insufficient Storage
INTERNAL_SERVER_ERROR500Server Error
LENGTH_REQUIRED411Length Required
LOCKED423Locked
METHOD_FAILURE420Method Failure
METHOD_NOT_ALLOWED405Method Not Allowed
MOVED_PERMANENTLY301Moved Permanently
MOVED_TEMPORARILY302Moved Temporarily
MULTI_STATUS207Multi-Status
MULTIPLE_CHOICES300Multiple Choices
NETWORK_AUTHENTICATION_REQUIRED511Network Authentication Required
NO_CONTENT204No Content
NON_AUTHORITATIVE_INFORMATION203Non Authoritative Information
NOT_ACCEPTABLE406Not Acceptable
NOT_FOUND404Not Found
NOT_IMPLEMENTED501Not Implemented
NOT_MODIFIED304Not Modified
OK200OK
PARTIAL_CONTENT206Partial Content
PAYMENT_REQUIRED402Payment Required
PERMANENT_REDIRECT308Permanent Redirect
PRECONDITION_FAILED412Precondition Failed
PRECONDITION_REQUIRED428Precondition Required
PROCESSING102Processing
PROXY_AUTHENTICATION_REQUIRED407Proxy Authentication Required
REQUEST_HEADER_FIELDS_TOO_LARGE431Request Header Fields Too Large
REQUEST_TIMEOUT408Request Timeout
REQUEST_TOO_LONG413Request Entity Too Large
REQUEST_URI_TOO_LONG414Request-URI Too Long
REQUESTED_RANGE_NOT_SATISFIABLE416Requested Range Not Satisfiable
RESET_CONTENT205Reset Content
SEE_OTHER303See Other
SERVICE_UNAVAILABLE503Service Unavailable
SWITCHING_PROTOCOLS101Switching Protocols
TEMPORARY_REDIRECT307Temporary Redirect
TOO_MANY_REQUESTS429Too Many Requests
UNAUTHORIZED401Unauthorized
UNPROCESSABLE_ENTITY422Unprocessable Entity
UNSUPPORTED_MEDIA_TYPE415Unsupported Media Type
USE_PROXY305Use Proxy

TypeScript

There is an included definition file that adds rules for use, comments, and links to official documentation.

Usage

import { HttpStatus } from '@empari/http-status-codes'
const httpStatus = new HttpStatus()

response.status(HttpStatus.OK).send('ok')

response.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
  error: httpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)
})

response.status(httpStatus.getStatusCode('Server Error')).send({
  error: 'Server Error'
})