1.0.1 • Published 2 years ago

@m4yours/uni-status-code v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

uni-status-code

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.

TypeScript or JavaScript. Completely library agnostic. No dependencies.

Installation

npm install @m4yours/uni-status-code --save

Usage (express 4.x)

import {
	ReasonPhrases,
	StatusCodes,
	getReasonPhrase,
	getStatusCode,
} from '@m4yours/uni-status-code';

response
	.status(StatusCodes.OK)
	.send(ReasonPhrases.OK);

response
	.status(StatusCodes.INTERNAL_SERVER_ERROR)
	.send({
		error: getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR)
	});

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

Codes

CodeConstantReason Phrase
100CONTINUEContinue
101SWITCHING_PROTOCOLSSwitching Protocols
102PROCESSINGProcessing
200OKOK
201CREATEDCreated
202ACCEPTEDAccepted
203NON_AUTHORITATIVE_INFORMATIONNon Authoritative Information
204NO_CONTENTNo Content
205RESET_CONTENTReset Content
206PARTIAL_CONTENTPartial Content
207MULTI_STATUSMulti-Status
300MULTIPLE_CHOICESMultiple Choices
301MOVED_PERMANENTLYMoved Permanently
302MOVED_TEMPORARILYMoved Temporarily
303SEE_OTHERSee Other
304NOT_MODIFIEDNot Modified
305USE_PROXYUse Proxy
307TEMPORARY_REDIRECTTemporary Redirect
308PERMANENT_REDIRECTPermanent Redirect
400BAD_REQUESTBad Request
401UNAUTHORIZEDUnauthorized
402PAYMENT_REQUIREDPayment Required
403FORBIDDENForbidden
404NOT_FOUNDNot Found
405METHOD_NOT_ALLOWEDMethod Not Allowed
406NOT_ACCEPTABLENot Acceptable
407PROXY_AUTHENTICATION_REQUIREDProxy Authentication Required
408REQUEST_TIMEOUTRequest Timeout
409CONFLICTConflict
410GONEGone
411LENGTH_REQUIREDLength Required
412PRECONDITION_FAILEDPrecondition Failed
413REQUEST_TOO_LONGRequest Entity Too Large
414REQUEST_URI_TOO_LONGRequest-URI Too Long
415UNSUPPORTED_MEDIA_TYPEUnsupported Media Type
416REQUESTED_RANGE_NOT_SATISFIABLERequested Range Not Satisfiable
417EXPECTATION_FAILEDExpectation Failed
418IM_A_TEAPOTI'm a teapot
419INSUFFICIENT_SPACE_ON_RESOURCEInsufficient Space on Resource
420METHOD_FAILUREMethod Failure
421MISDIRECTED_REQUESTMisdirected Request
422UNPROCESSABLE_ENTITYUnprocessable Entity
423LOCKEDLocked
424FAILED_DEPENDENCYFailed Dependency
428PRECONDITION_REQUIREDPrecondition Required
429TOO_MANY_REQUESTSToo Many Requests
431REQUEST_HEADER_FIELDS_TOO_LARGERequest Header Fields Too Large
451UNAVAILABLE_FOR_LEGAL_REASONSUnavailable For Legal Reasons
500INTERNAL_SERVER_ERRORInternal Server Error
501NOT_IMPLEMENTEDNot Implemented
502BAD_GATEWAYBad Gateway
503SERVICE_UNAVAILABLEService Unavailable
504GATEWAY_TIMEOUTGateway Timeout
505HTTP_VERSION_NOT_SUPPORTEDHTTP Version Not Supported
507INSUFFICIENT_STORAGEInsufficient Storage
511NETWORK_AUTHENTICATION_REQUIREDNetwork Authentication Required