Core HTTP status codes (1xx-5xx) following the IANA HTTP Status Code Registry with multiple access patterns for flexible usage.
The main status object provides multiple ways to access status code information.
/**
* Main status object with multiple access patterns
*/
interface StatusObject {
// Numeric keys return status names
100: "Continue";
200: "OK";
404: "Not Found";
500: "Internal Server Error";
[code: number]: string;
// Named constants return status codes
CONTINUE: 100;
OK: 200;
NOT_FOUND: 404;
INTERNAL_SERVER_ERROR: 500;
[name: string]: number;
// Information accessors
"100_NAME": "CONTINUE";
"100_MESSAGE": "The server has received the request headers and the client should proceed to send the request body.";
"100_CLASS": "1xx";
[key: `${number}_NAME`]: string;
[key: `${number}_MESSAGE`]: string;
[key: `${number}_CLASS`]: string;
}Usage Examples:
import status from "http-status";
// Get status name from numeric code
const statusName = status[200]; // "OK"
const errorName = status[404]; // "Not Found"
// Get numeric code from constant name
const okCode = status.OK; // 200
const notFoundCode = status.NOT_FOUND; // 404
// Get constant name (useful for logging)
const constantName = status["200_NAME"]; // "OK"
const errorConstant = status["404_NAME"]; // "NOT_FOUND"
// Get descriptive message
const message = status["200_MESSAGE"]; // "Standard response for successful HTTP requests."
const errorMessage = status["404_MESSAGE"]; // "The requested resource could not be found..."
// Get status class
const successClass = status["200_CLASS"]; // "2xx"
const errorClass = status["404_CLASS"]; // "4xx"Status codes indicating an interim response for communicating connection status or request progress.
// 1xx Informational status codes
interface InformationalCodes {
100: "Continue";
CONTINUE: 100;
"100_NAME": "CONTINUE";
"100_MESSAGE": "The server has received the request headers and the client should proceed to send the request body.";
"100_CLASS": "1xx";
101: "Switching Protocols";
SWITCHING_PROTOCOLS: 101;
"101_NAME": "SWITCHING_PROTOCOLS";
"101_MESSAGE": "The requester has asked the server to switch protocols and the server has agreed to do so.";
"101_CLASS": "1xx";
102: "Processing";
PROCESSING: 102;
"102_NAME": "PROCESSING";
"102_MESSAGE": "A WebDAV request may contain many sub-requests involving file operations, requiring a long time to complete the request.";
"102_CLASS": "1xx";
103: "Early Hints";
EARLY_HINTS: 103;
"103_NAME": "EARLY_HINTS";
"103_MESSAGE": "Used to return some response headers before final HTTP message.";
"103_CLASS": "1xx";
}Status codes indicating that the client's request was successfully received, understood, and accepted.
// 2xx Successful status codes
interface SuccessfulCodes {
200: "OK";
OK: 200;
"200_NAME": "OK";
"200_MESSAGE": "Standard response for successful HTTP requests.";
"200_CLASS": "2xx";
201: "Created";
CREATED: 201;
"201_NAME": "CREATED";
"201_MESSAGE": "The request has been fulfilled, resulting in the creation of a new resource.";
"201_CLASS": "2xx";
202: "Accepted";
ACCEPTED: 202;
"202_NAME": "ACCEPTED";
"202_MESSAGE": "The request has been accepted for processing, but the processing has not been completed.";
"202_CLASS": "2xx";
203: "Non-Authoritative Information";
NON_AUTHORITATIVE_INFORMATION: 203;
"203_NAME": "NON_AUTHORITATIVE_INFORMATION";
"203_MESSAGE": "The server is a transforming proxy that received a 200 OK from its origin, but is returning a modified version of the origin's response.";
"203_CLASS": "2xx";
204: "No Content";
NO_CONTENT: 204;
"204_NAME": "NO_CONTENT";
"204_MESSAGE": "The server successfully processed the request and is not returning any content.";
"204_CLASS": "2xx";
205: "Reset Content";
RESET_CONTENT: 205;
"205_NAME": "RESET_CONTENT";
"205_MESSAGE": "The server successfully processed the request, but is not returning any content. Unlike a 204 response, this response requires that the requester reset the document view.";
"205_CLASS": "2xx";
206: "Partial Content";
PARTIAL_CONTENT: 206;
"206_NAME": "PARTIAL_CONTENT";
"206_MESSAGE": "The server is delivering only part of the resource due to a range header sent by the client.";
"206_CLASS": "2xx";
207: "Multi Status";
MULTI_STATUS: 207;
"207_NAME": "MULTI_STATUS";
"207_MESSAGE": "The message body that follows is by default an XML message and can contain a number of separate response codes.";
"207_CLASS": "2xx";
208: "Already Reported";
ALREADY_REPORTED: 208;
"208_NAME": "ALREADY_REPORTED";
"208_MESSAGE": "The members of a DAV binding have already been enumerated in a preceding part of the response.";
"208_CLASS": "2xx";
226: "IM Used";
IM_USED: 226;
"226_NAME": "IM_USED";
"226_MESSAGE": "The server has fulfilled a request for the resource, and the response is a representation of the result of one or more instance-manipulations.";
"226_CLASS": "2xx";
}Status codes indicating that further action needs to be taken by the user agent to fulfill the request.
// 3xx Redirection status codes
interface RedirectionCodes {
300: "Multiple Choices";
MULTIPLE_CHOICES: 300;
"300_NAME": "MULTIPLE_CHOICES";
"300_MESSAGE": "Indicates multiple options for the resource from which the client may choose.";
"300_CLASS": "3xx";
301: "Moved Permanently";
MOVED_PERMANENTLY: 301;
"301_NAME": "MOVED_PERMANENTLY";
"301_MESSAGE": "This and all future requests should be directed to the given URI.";
"301_CLASS": "3xx";
302: "Found";
FOUND: 302;
"302_NAME": "FOUND";
"302_MESSAGE": "This is an example of industry practice contradicting the standard.";
"302_CLASS": "3xx";
303: "See Other";
SEE_OTHER: 303;
"303_NAME": "SEE_OTHER";
"303_MESSAGE": "The response to the request can be found under another URI using the GET method.";
"303_CLASS": "3xx";
304: "Not Modified";
NOT_MODIFIED: 304;
"304_NAME": "NOT_MODIFIED";
"304_MESSAGE": "Indicates that the resource has not been modified since the version specified by the request headers.";
"304_CLASS": "3xx";
305: "Use Proxy";
USE_PROXY: 305;
"305_NAME": "USE_PROXY";
"305_MESSAGE": "The requested resource is available only through a proxy, the address for which is provided in the response.";
"305_CLASS": "3xx";
306: "Switch Proxy";
SWITCH_PROXY: 306;
"306_NAME": "SWITCH_PROXY";
"306_MESSAGE": "No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"";
"306_CLASS": "3xx";
307: "Temporary Redirect";
TEMPORARY_REDIRECT: 307;
"307_NAME": "TEMPORARY_REDIRECT";
"307_MESSAGE": "In this case, the request should be repeated with another URI; however, future requests should still use the original URI.";
"307_CLASS": "3xx";
308: "Permanent Redirect";
PERMANENT_REDIRECT: 308;
"308_NAME": "PERMANENT_REDIRECT";
"308_MESSAGE": "The request and all future requests should be repeated using another URI.";
"308_CLASS": "3xx";
}Status codes indicating that the client seems to have erred.
// 4xx Client Error status codes (partial list - major codes)
interface ClientErrorCodes {
400: "Bad Request";
BAD_REQUEST: 400;
"400_NAME": "BAD_REQUEST";
"400_MESSAGE": "The server cannot or will not process the request due to an apparent client error.";
"400_CLASS": "4xx";
401: "Unauthorized";
UNAUTHORIZED: 401;
"401_NAME": "UNAUTHORIZED";
"401_MESSAGE": "Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided.";
"401_CLASS": "4xx";
403: "Forbidden";
FORBIDDEN: 403;
"403_NAME": "FORBIDDEN";
"403_MESSAGE": "The request was valid, but the server is refusing action.";
"403_CLASS": "4xx";
404: "Not Found";
NOT_FOUND: 404;
"404_NAME": "NOT_FOUND";
"404_MESSAGE": "The requested resource could not be found but may be available in the future.";
"404_CLASS": "4xx";
405: "Method Not Allowed";
METHOD_NOT_ALLOWED: 405;
"405_NAME": "METHOD_NOT_ALLOWED";
"405_MESSAGE": "A request method is not supported for the requested resource.";
"405_CLASS": "4xx";
418: "I'm a teapot";
IM_A_TEAPOT: 418;
"418_NAME": "IM_A_TEAPOT";
"418_MESSAGE": "Any attempt to brew coffee with a teapot should result in the error code \"418 I'm a teapot\".";
"418_CLASS": "4xx";
429: "Too Many Requests";
TOO_MANY_REQUESTS: 429;
"429_NAME": "TOO_MANY_REQUESTS";
"429_MESSAGE": "The user has sent too many requests in a given amount of time.";
"429_CLASS": "4xx";
}Status codes indicating that the server is aware that it has erred or is incapable of performing the requested method.
// 5xx Server Error status codes
interface ServerErrorCodes {
500: "Internal Server Error";
INTERNAL_SERVER_ERROR: 500;
"500_NAME": "INTERNAL_SERVER_ERROR";
"500_MESSAGE": "A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.";
"500_CLASS": "5xx";
501: "Not Implemented";
NOT_IMPLEMENTED: 501;
"501_NAME": "NOT_IMPLEMENTED";
"501_MESSAGE": "The server either does not recognize the request method, or it lacks the ability to fulfil the request.";
"501_CLASS": "5xx";
502: "Bad Gateway";
BAD_GATEWAY: 502;
"502_NAME": "BAD_GATEWAY";
"502_MESSAGE": "The server was acting as a gateway or proxy and received an invalid response from the upstream server.";
"502_CLASS": "5xx";
503: "Service Unavailable";
SERVICE_UNAVAILABLE: 503;
"503_NAME": "SERVICE_UNAVAILABLE";
"503_MESSAGE": "The server is currently unavailable (because it is overloaded or down for maintenance).";
"503_CLASS": "5xx";
504: "Gateway Time-out";
GATEWAY_TIMEOUT: 504;
"504_NAME": "GATEWAY_TIMEOUT";
"504_MESSAGE": "The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.";
"504_CLASS": "5xx";
511: "Network Authentication Required";
NETWORK_AUTHENTICATION_REQUIRED: 511;
"511_NAME": "NETWORK_AUTHENTICATION_REQUIRED";
"511_MESSAGE": "The client needs to authenticate to gain network access.";
"511_CLASS": "5xx";
}