Need help with http-status-codes?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

prettymuchbryce
506 Stars 71 Forks MIT License 72 Commits 3 Opened issues

Description

Constants enumerating the HTTP status codes. All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and RFC2518 (WebDAV) are supported.

Services available

!
?

Need anything else?

Contributors list

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

| Code | Constant | Reason Phrase | | ---- | ------------------------------- | ------------------------------- | | 100 | CONTINUE | Continue | | 101 | SWITCHINGPROTOCOLS | Switching Protocols | | 102 | PROCESSING | Processing | | 200 | OK | OK | | 201 | CREATED | Created | | 202 | ACCEPTED | Accepted | | 203 | NONAUTHORITATIVEINFORMATION | Non Authoritative Information | | 204 | NOCONTENT | No Content | | 205 | RESETCONTENT | Reset Content | | 206 | PARTIALCONTENT | Partial Content | | 207 | MULTISTATUS | Multi-Status | | 300 | MULTIPLECHOICES | Multiple Choices | | 301 | MOVEDPERMANENTLY | Moved Permanently | | 302 | MOVEDTEMPORARILY | Moved Temporarily | | 303 | SEEOTHER | See Other | | 304 | NOTMODIFIED | Not Modified | | 305 | USEPROXY | Use Proxy | | 307 | TEMPORARYREDIRECT | Temporary Redirect | | 308 | PERMANENTREDIRECT | Permanent Redirect | | 400 | BADREQUEST | Bad Request | | 401 | UNAUTHORIZED | Unauthorized | | 402 | PAYMENTREQUIRED | Payment Required | | 403 | FORBIDDEN | Forbidden | | 404 | NOTFOUND | Not Found | | 405 | METHODNOTALLOWED | Method Not Allowed | | 406 | NOTACCEPTABLE | Not Acceptable | | 407 | PROXYAUTHENTICATIONREQUIRED | Proxy Authentication Required | | 408 | REQUESTTIMEOUT | Request Timeout | | 409 | CONFLICT | Conflict | | 410 | GONE | Gone | | 411 | LENGTHREQUIRED | Length Required | | 412 | PRECONDITIONFAILED | Precondition Failed | | 413 | REQUESTTOOLONG | Request Entity Too Large | | 414 | REQUESTURITOOLONG | Request-URI Too Long | | 415 | UNSUPPORTEDMEDIATYPE | Unsupported Media Type | | 416 | REQUESTEDRANGENOTSATISFIABLE | Requested Range Not Satisfiable | | 417 | EXPECTATIONFAILED | Expectation Failed | | 418 | IMATEAPOT | I'm a teapot | | 419 | INSUFFICIENTSPACEONRESOURCE | Insufficient Space on Resource | | 420 | METHODFAILURE | Method Failure | | 422 | UNPROCESSABLEENTITY | Unprocessable Entity | | 423 | LOCKED | Locked | | 424 | FAILEDDEPENDENCY | Failed Dependency | | 428 | PRECONDITIONREQUIRED | Precondition Required | | 429 | TOOMANYREQUESTS | Too Many Requests | | 431 | REQUESTHEADERFIELDSTOOLARGE | Request Header Fields Too Large | | 451 | UNAVAILABLEFORLEGALREASONS | Unavailable For Legal Reasons | | 500 | INTERNALSERVERERROR | Internal Server Error | | 501 | NOTIMPLEMENTED | Not Implemented | | 502 | BADGATEWAY | Bad Gateway | | 503 | SERVICEUNAVAILABLE | Service Unavailable | | 504 | GATEWAYTIMEOUT | Gateway Timeout | | 505 | HTTPVERSIONNOTSUPPORTED | HTTP Version Not Supported | | 507 | INSUFFICIENTSTORAGE | Insufficient Storage | | 511 | NETWORKAUTHENTICATION_REQUIRED | Network 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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.