Constants enumerating the HTTP status codes. Based on the Java Apache HttpStatus API.
The npm package "http-status-codes" is an essential tool for developers working with web technologies, providing an easy-to-use repository of constants for HTTP status codes. This node module simplifies the management of HTTP status codes by offering a comprehensive list of status code references, such as OK, NOT_FOUND, and INTERNAL_SERVER_ERROR, directly derived from the Java Apache HttpStatus API. By integrating "http-status-codes" into their projects, developers can enhance code readability and reduce the likelihood of errors associated with using incorrect status codes, ensuring their server responses are accurate and standards-compliant.
To utilize this beneficial package, developers can simply execute the command "npm install http-status-codes" in their project environment. This installation provides immediate access to all HTTP status codes, allowing for quick and easy implementation in various applications, including web servers and client-side utilities. The "http-status-codes" package supports both common JS and ES module imports, making it versatile for integration in different JavaScript environments. By using this npm package, developers can significantly streamline their codebase, making their development process more efficient and their applications more robust and maintainable.
The "http-status-codes" module not only facilitates a more organized code structure but also aids in debugging and testing processes by providing developers with precise status codes. This reduces the time spent on tracing HTTP errors and enhances the overall quality of web services. Additionally, the module is continually updated to reflect any changes in the HTTP specification, ensuring developers have access to the latest status codes and best practices in handling HTTP responses.
Constants enumerating the HTTP status codes. Based on the Java Apache HttpStatus API...
Read moreCore dependencies of this npm package and its dev dependencies.
@types/fs-extra, @types/jest, @types/markdown-table, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, eslint, eslint-config-airbnb-typescript, eslint-plugin-import, fs-extra, jest, markdown-table, ts-jest, ts-morph, ts-node, typescript
A README file for the http-status-codes code repository. View Code
Constants enumerating the HTTP status codes. Based on the Java Apache HttpStatus API.
All status codes defined in the following RFCs are supported:
TypeScript or JavaScript. Completely library agnostic. No dependencies.
npm install http-status-codes --save
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'
});
Code | Constant | Reason Phrase |
---|---|---|
100 | CONTINUE | Continue |
101 | SWITCHING_PROTOCOLS | Switching Protocols |
102 | PROCESSING | Processing |
103 | EARLY_HINTS | Early Hints |
200 | OK | OK |
201 | CREATED | Created |
202 | ACCEPTED | Accepted |
203 | NON_AUTHORITATIVE_INFORMATION | Non Authoritative Information |
204 | NO_CONTENT | No Content |
205 | RESET_CONTENT | Reset Content |
206 | PARTIAL_CONTENT | Partial Content |
207 | MULTI_STATUS | Multi-Status |
300 | MULTIPLE_CHOICES | Multiple Choices |
301 | MOVED_PERMANENTLY | Moved Permanently |
302 | MOVED_TEMPORARILY | Moved Temporarily |
303 | SEE_OTHER | See Other |
304 | NOT_MODIFIED | Not Modified |
305 | USE_PROXY | Use Proxy |
307 | TEMPORARY_REDIRECT | Temporary Redirect |
308 | PERMANENT_REDIRECT | Permanent Redirect |
400 | BAD_REQUEST | Bad Request |
401 | UNAUTHORIZED | Unauthorized |
402 | PAYMENT_REQUIRED | Payment Required |
403 | FORBIDDEN | Forbidden |
404 | NOT_FOUND | Not Found |
405 | METHOD_NOT_ALLOWED | Method Not Allowed |
406 | NOT_ACCEPTABLE | Not Acceptable |
407 | PROXY_AUTHENTICATION_REQUIRED | Proxy Authentication Required |
408 | REQUEST_TIMEOUT | Request Timeout |
409 | CONFLICT | Conflict |
410 | GONE | Gone |
411 | LENGTH_REQUIRED | Length Required |
412 | PRECONDITION_FAILED | Precondition Failed |
413 | REQUEST_TOO_LONG | Request Entity Too Large |
414 | REQUEST_URI_TOO_LONG | Request-URI Too Long |
415 | UNSUPPORTED_MEDIA_TYPE | Unsupported Media Type |
416 | REQUESTED_RANGE_NOT_SATISFIABLE | Requested Range Not Satisfiable |
417 | EXPECTATION_FAILED | Expectation Failed |
418 | IM_A_TEAPOT | I'm a teapot |
419 | INSUFFICIENT_SPACE_ON_RESOURCE | Insufficient Space on Resource |
420 | METHOD_FAILURE | Method Failure |
421 | MISDIRECTED_REQUEST | Misdirected Request |
422 | UNPROCESSABLE_ENTITY | Unprocessable Entity |
423 | LOCKED | Locked |
424 | FAILED_DEPENDENCY | Failed Dependency |
426 | UPGRADE_REQUIRED | Upgrade Required |
428 | PRECONDITION_REQUIRED | Precondition Required |
429 | TOO_MANY_REQUESTS | Too Many Requests |
431 | REQUEST_HEADER_FIELDS_TOO_LARGE | Request Header Fields Too Large |
451 | UNAVAILABLE_FOR_LEGAL_REASONS | Unavailable For Legal Reasons |
500 | INTERNAL_SERVER_ERROR | Internal Server Error |
501 | NOT_IMPLEMENTED | Not Implemented |
502 | BAD_GATEWAY | Bad Gateway |
503 | SERVICE_UNAVAILABLE | Service Unavailable |
504 | GATEWAY_TIMEOUT | Gateway Timeout |
505 | HTTP_VERSION_NOT_SUPPORTED | HTTP Version Not Supported |
507 | INSUFFICIENT_STORAGE | Insufficient Storage |
511 | NETWORK_AUTHENTICATION_REQUIRED | Network Authentication Required |
http-status-codes v2 is mostly backwards compatible with v1. There is a single breaking change and two recommended changes.
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.
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.
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.
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.
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.