🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

http-response-status-code

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-response-status-code

A lightweight utility for retrieving HTTP status codes, names, and descriptions. Easily validate, categorize, and manage HTTP responses with built-in methods for informational, success, redirection, client, and server error codes.

1.7.5
latest
Source
npm
Version published
Weekly downloads
819
9.49%
Maintainers
0
Weekly downloads
 
Created
Source

HTTP Response Status Code

All HTTP Status Codes from Wikipedia - List of HTTP status codes

GitHub Workflow Status npm version GitHub license GitHub Issues Codacy Badge Codacy Badge npms.io (final) npm Socket Badge GitHub Pages Github Sponsors Open Collective Buy Me A Coffee Patreon PayPal

Table of Content

Installation

npm install http-response-status-code

Usage (Example)

var STATUS_CODES = require('http-response-status-code');
// OR
import * as STATUS_CODES from 'http-response-status-code';
// OR
import { OK, getStatusName, CODES } from 'http-response-status-code';

console.log(STATUS_CODES.getStatusName(STATUS_CODES.OK));
// OK

console.log(getStatusName(OK));
// OK

console.log(OK);
// 200

console.log(STATUS_CODES.getStatusDescription(STATUS_CODES.INTERNAL_SERVER_ERROR));
// Internal Server Error

console.log(STATUS_CODES.getStatusCode("IM_A_TEAPOT"));
// 418

console.log(STATUS_CODES.CODES.HTTP_CODE_200);
// 200

res.status(STATUS_CODES.INTERNAL_SERVER_ERROR).end()
// OR
res.status(STATUS_CODES.CODES.HTTP_CODE_500).end()


res.status(STATUS_CODES.BAD_REQUEST).send(STATUS_CODES.getStatusDescription(STATUS_CODES.BAD_REQUEST));
// OR
res.status(STATUS_CODES.CODES.HTTP_CODE_400).send(STATUS_CODES.getStatusDescription(STATUS_CODES.CODES.HTTP_CODE_400));

res.status(STATUS_CODES.getStatusCode("NOT_FOUND")).sendFile('/absolute/path/to/404.png');
// OR
res.status(STATUS_CODES.CODES.HTTP_CODE_404).sendFile('/absolute/path/to/404.png');

Toolset Overview

1. Get Status Code

Returns the HTTP status code from status code name.

Parameters

  • name (String): The name of the status code (e.g., "IM_A_TEAPOT").

Returns

  • code (number): The code number of the status if code exists.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getStatusCode("IM_A_TEAPOT")); // 418

2. Get Status Name

Returns the HTTP status code name from status code (e.g., 418).

Parameters

  • code (number): The code number of the status (e.g., 418).

Returns

  • name (String): The name of the status code if name exists.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getStatusName(418)); // "IM_A_TEAPOT"

3. Get Status Description

Returns the status description from HTTP status code (e.g., 418).

Parameters

  • code (number): The code number of the status (e.g., 418).

Returns

  • name (String): The description of the status code if code exists.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getStatusDescription(500)); // "Internal Server Error"

4. Informational Code Check

Determines whether the specified status code represents an informational status.

Parameters

  • code (number): The code number of the status (e.g., 100).

Returns

  • isInformational (boolean): Returns true if the status code represents a informational status code (1xx), otherwise returns false.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isInformational(100)); // True
console.log(STATUS_CODES.isInformational(200)); // False

5. List Informational Codes

Provides a list of all the informational HTTP status codes.

Returns

  • result (number[]): An array of all the informational HTTP status codes.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getInformationalCodes()); // [100, 101, ...]

6. Success Code Check

Determines whether the specified status code represents a success status.

Parameters

  • code (number): The code number of the status (e.g., 200).

Returns

  • isSuccess (boolean): Returns true if the status code represents a success status code (2xx), otherwise returns false.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isSuccess(200)); // True
console.log(STATUS_CODES.isSuccess(100)); // False

7. List Success Codes

Provides a list of all the success HTTP status codes.

Returns

  • result (number[]): An array of all the success HTTP status codes.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getSuccessCodes()); // [200, 201, ...]

8. Redirection Code Check

Determines whether the specified status code represents a redirection status.

Parameters

  • code (number): The code number of the status (e.g., 300).

Returns

  • isRedirectional (boolean): Returns true if the status code represents a redirection status code (3xx), otherwise returns false.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isRedirectional(300)); // True
console.log(STATUS_CODES.isRedirectional(100)); // False

9. List Redirection Codes

Provides a list of all the redirection HTTP status codes.

Returns

  • result (number[]): An array of all the redirection HTTP status codes.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getRedirectionalCodes()); // [300, 301, ...]

10. Client Error Code Check

Determines whether the specified status code represents a client side error status.

Parameters

  • code (number): The code number of the status (e.g., 400).

Returns

  • isClientError (boolean): Returns true if the status code represents a client side error code (4xx), otherwise returns false.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isClientError(400)); // True
console.log(STATUS_CODES.isClientError(100)); // False

11. List Client Side Error Codes

Provides a list of all the client side error HTTP status codes.

Returns

  • result (number[]): An array of all the client side error HTTP status codes.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getClientErrorCodes()); // [400, 401, ...]

12. Server Error Code Check

Determines whether the specified status code represents a server side error status.

Parameters

  • code (number): The code number of the status (e.g., 500).

Returns

  • isServerError (boolean): Returns true if the status code represents a server side error code (5xx), otherwise returns false.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isServerError(500)); // True
console.log(STATUS_CODES.isServerError(100)); // False

13. List Server Side Error Codes

Provides a list of all the server side error HTTP status codes.

Returns

  • result (number[]): An array of all the server side error HTTP status codes.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getServerErrorCodes()); // [500, 501, ...]

14. Valid Code Check

Validates whether the provided status code is recognized as valid.

Parameters

  • code (number): The code number of the status (e.g., 500).

Returns

  • isValidStatusCode (boolean): Returns true if the status code represents a valid status code (1xx, 2xx, ..., 5xx), otherwise returns false.
  • Error: An error object if something goes wrong, containing details about the issue.

Example (Stackblitz)

var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isValidStatusCode(500)); // True
console.log(STATUS_CODES.isValidStatusCode(999)); // False

Status Codes

CodeEnumNameDescription
100HTTP_CODE_100CONTINUEContinue
101HTTP_CODE_101SWITCHING_PROTOCOLSSwitching Protocols
102HTTP_CODE_102PROCESSINGProcessing
103HTTP_CODE_103EARLY_HINTSEarly Hints
122HTTP_CODE_122TOO_LONGToo Long
200HTTP_CODE_200OKOK
201HTTP_CODE_201CREATEDCreated
202HTTP_CODE_202ACCEPTEDAccepted
203HTTP_CODE_203NON_AUTHORITATIVE_INFORMATIONNon Authoritative Information
204HTTP_CODE_204NO_CONTENTNo Content
205HTTP_CODE_205RESET_CONTENTReset Content
206HTTP_CODE_206PARTIAL_CONTENTPartial Content
207HTTP_CODE_207MULTI_STATUSMulti-Status
208HTTP_CODE_208ALREADY_REPORTEDAlready Reported
226HTTP_CODE_226IM_USEDIM Used
300HTTP_CODE_300MULTIPLE_CHOICESMultiple Choices
301HTTP_CODE_301MOVED_PERMANENTLYMoved Permanently
302HTTP_CODE_302MOVED_TEMPORARILYMoved Temporarily
303HTTP_CODE_303SEE_OTHERSee Other
304HTTP_CODE_304NOT_MODIFIEDNot Modified
305HTTP_CODE_305USE_PROXYUse Proxy
306HTTP_CODE_306SWITCH_PROXYSwitch Proxy
307HTTP_CODE_307TEMPORARY_REDIRECTTemporary Redirect
308HTTP_CODE_308PERMANENT_REDIRECTPermanent Redirect
400HTTP_CODE_400BAD_REQUESTBad Request
401HTTP_CODE_401UNAUTHORIZEDUnauthorized
402HTTP_CODE_402PAYMENT_REQUIREDPayment Required
403HTTP_CODE_403FORBIDDENForbidden
404HTTP_CODE_404NOT_FOUNDNot Found
405HTTP_CODE_405METHOD_NOT_ALLOWEDMethod Not Allowed
406HTTP_CODE_406NOT_ACCEPTABLENot Acceptable
407HTTP_CODE_407PROXY_AUTHENTICATION_REQUIREDProxy Authentication Required
408HTTP_CODE_408REQUEST_TIMEOUTRequest Timeout
409HTTP_CODE_409CONFLICTConflict
410HTTP_CODE_410GONEGone
411HTTP_CODE_411LENGTH_REQUIREDLength Required
412HTTP_CODE_412PRECONDITION_FAILEDPrecondition Failed
413HTTP_CODE_413REQUEST_TOO_LONGRequest Entity Too Large
414HTTP_CODE_414REQUEST_URI_TOO_LONGRequest-URI Too Long
415HTTP_CODE_415UNSUPPORTED_MEDIA_TYPEUnsupported Media Type
416HTTP_CODE_416REQUESTED_RANGE_NOT_SATISFIABLERequested Range Not Satisfiable
417HTTP_CODE_417EXPECTATION_FAILEDExpectation Failed
418HTTP_CODE_418IM_A_TEAPOTI'm a teapot
419HTTP_CODE_419INSUFFICIENT_SPACE_ON_RESOURCEInsufficient Space on Resource
420HTTP_CODE_420METHOD_FAILUREMethod Failure
421HTTP_CODE_421MISDIRECTED_REQUESTMisdirected Request
422HTTP_CODE_422UNPROCESSABLE_ENTITYUnprocessable Entity
423HTTP_CODE_423LOCKEDLocked
424HTTP_CODE_424FAILED_DEPENDENCYFailed Dependency
425HTTP_CODE_425TOO_EARLYToo Early
426HTTP_CODE_426UPGRADE_REQUIREDUpgrade Required
428HTTP_CODE_428PRECONDITION_REQUIREDPrecondition Required
429HTTP_CODE_429TOO_MANY_REQUESTSToo Many Requests
431HTTP_CODE_431REQUEST_HEADER_FIELDS_TOO_LARGERequest Header Fields Too Large
451HTTP_CODE_451UNAVAILABLE_FOR_LEGAL_REASONSUnavailable For Legal Reasons
500HTTP_CODE_500INTERNAL_SERVER_ERRORInternal Server Error
501HTTP_CODE_501NOT_IMPLEMENTEDNot Implemented
502HTTP_CODE_502BAD_GATEWAYBad Gateway
503HTTP_CODE_503SERVICE_UNAVAILABLEService Unavailable
504HTTP_CODE_504GATEWAY_TIMEOUTGateway Timeout
505HTTP_CODE_505HTTP_VERSION_NOT_SUPPORTEDHTTP Version Not Supported
506HTTP_CODE_506VARIANT_ALSO_NEGOTIATESVariant Also Negotiates
507HTTP_CODE_507INSUFFICIENT_STORAGEInsufficient Storage
508HTTP_CODE_508LOOP_DETECTEDLoop Detected
510HTTP_CODE_510NOT_EXTENDEDNot Extended
511HTTP_CODE_511NETWORK_AUTHENTICATION_REQUIREDNetwork Authentication Required

People

The original author of the project is Himanshu Bansal

Donations

This is all voluntary work, so if you want to support my efforts you can

You can also use the following:

BTC: qzqmpxux3m56qqhz465u8022q9z63w2sysq4u9ltwj

ETH: 0x1D59a291391a3CE17C63D5dC50F258Dc0Ab62889

License

http-response-status-code project is open-sourced software licensed under the MIT license by Himanshu Bansal.

Keywords

Http

FAQs

Package last updated on 18 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts