2.3.0 • Published 2 years ago

http-status-codes v2.3.0

Weekly downloads
663,302
License
MIT
Repository
github
Last release
2 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.

TypeScript or JavaScript. Completely library agnostic. No dependencies.

Installation

npm install http-status-codes --save

Usage (express 4.x)

import {
	ReasonPhrases,
	StatusCodes,
	getReasonPhrase,
	getStatusCode,
} from 'http-status-codes';

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
103EARLY_HINTSEarly Hints
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
426UPGRADE_REQUIREDUpgrade Required
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

Migrating from v1.x.x

http-status-codes v2 is mostly backwards compatible with v1. There is a single breaking change and two recommended changes.

Breaking Change 'Server Error'

The reason phrase for the status code 500 has been changed from "Server Error" to "Internal Server Error". This is the correct phrase according to RFC7231. If you are migrating from v1, and have code that relies on the result of getStatusText(500) or getReasonPhrase('Server Error'), then this could affect you.

Non-breaking change getStatusText renamed getReasonPhrase

The function getStatusText has been renamed to getReasonPhrase. The old function is still available, but may be deprecated in a future version. To fix this simply rename instances of getStatusText() to getReasonPhrase(). The function is otherwise the same as it was before.

Non-breaking change StatusCodes

In http-status-codes v1, Status Codes were exported directly from the top-level module. i.e. HttpStatus.OK. In v2 all Status Codes live under an object called StatusCodes. i.e. HttpStatus.StatusCodes.OK. We made this change to cater to TypeScript users who prefer a dedicated value with an enum type. The previous values are still exported, but we won't continue to update them. Please migrate if you're using the old-style imports.

Proposing a new status code

If you'd like to propose a new status code, feel free to update "codes.json" with the necessary information and open a pull request. There is no need to modify source code or even this README. This is done automatically by npm run update-codes.

In general, we try to include only codes that have an official RFC and have been approved, however exceptions can be made if the code is already in widespread use in the wild.

Steps to build and publish

npm run update-codes
npm run test
npm run build
npm version [major | minor | patch]
npm publish

After releasing, please add release notes via GitHub Releases.

first-library-saroj@cieslar-ticketing-common/common@qiibee/qb-api@solanafm/api@kbox/server@case-app/angular-library@case-app/nest-library@casejs/angular-library@casejs/nest-librarynode-osm-apiusers-weblib-imagehoney-lending-eligibilityhoney-lending-platform-adapterhoney-lending-transactions@lunares/lunaresamazon-advertising-api-nodejs-sdk@asesconsulting/merlin-auth@rentiohq/sharedhost-panel@vazee/vz-vendor-sendinbluecommie-service@floms-inc/response-raidersingpass-myinfo-oidc-helperrectified-iocaccess-decision-managerningilin@persistr/clientgraphql2rest-tmppurascents-scriptsunique-segment-idbms-backend-apibase-rest-apipresentihexd@framework100500/commontrowel-wikiloadarchivejob-ad-statistics-api@charlesiqueira/common@sellics/profitalpha.api.expressfavo-paygraphql2rest-jsexpress-typescript-mongoose-starterelixir-health-serverinvoiceservicerally-db-migrations-testcl-serveexternal-api-analyticslittle-dev-server@tiemma/swagger-jsdoc-responsefcenail-servermagaya-container-trackingcontrolapp-backend@polygonjs/editorrally-aping-poc-logindekoa-hd@everreal/er-common-helpers@nkvrntickets/commons@moderno/serveresnext-serverdelivery-parameterselcoedjeibsr0w3fqapp-serverinsomnia-plugin-pdf-report@misakey/api@misakey/core@mcgordonite/theia-filesystem@map-colonies/external-to-osm-tag-mapping@moritzko_bbc/emulator-core@renito/commonerror-msgs@lotojs/core@cbidigital/heron-commonnpm-git-lab-testnpm-test-public-packagenpm-test-public-package-express-exampleisa-syncttaku-apinext-sugarretool-proxyapi-projectcancerbero-backend@tegebu/ballon@tegebu/bgg-batchadventure.scheduling.api.wrapper@spetushkou/api-expressjsjourney-serviceids-sql-adapter@k8s-tickets/k8s-common-tickets@mtth/lerror@envuso/routing@lukeshay/next-middlewaretaf-connectkoa-hare@envuso/framework@kununu/kununu-utilsgate-backend
2.3.0

2 years ago

2.2.0

3 years ago

2.1.5-beta.1

5 years ago

2.1.5-beta.0

5 years ago

2.1.4

5 years ago

2.1.4-beta.5

5 years ago

2.1.4-beta.4

5 years ago

2.1.4-beta.3

5 years ago

2.1.4-beta.2

5 years ago

2.1.4-beta.1

5 years ago

2.1.4-beta.0

5 years ago

2.1.3

5 years ago

2.1.3-beta.0

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

2.0.0-beta.9

5 years ago

2.0.0-beta.8

5 years ago

2.0.0-beta.7

5 years ago

2.0.0-beta.2

5 years ago

2.0.0-beta.1

5 years ago

2.0.0-beta.0

5 years ago

2.0.0-beta.6

5 years ago

2.0.0-beta.5

5 years ago

2.0.0-beta.4

5 years ago

2.0.0-beta.3

5 years ago

1.4.0

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.6

8 years ago

1.0.6

9 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

12 years ago

1.0.1

12 years ago

1.0.0

12 years ago