HTTP Response Status Code Utilities

1.7.5 · active · verified Wed Apr 22

This package, `http-response-status-code`, provides a lightweight and comprehensive utility for interacting with HTTP status codes, names, and descriptions. Currently at version 1.7.5, it offers a stable API for retrieving details, validating codes, and categorizing them into informational, success, redirection, client error, and server error groups. The library differentiates itself by providing a full suite of helper functions, such as `getStatusName`, `getStatusDescription`, `getNotFound`, and dedicated checks like `isInformationalCode` or `isClientErrorCode`, in addition to exposing all standard HTTP status codes as named exports. Its release cadence appears to be moderate, with minor updates focusing on feature additions like the "Toolset Overview" in 1.7.2 and continuous code hygiene improvements. It ships with TypeScript types, ensuring robust usage in modern JavaScript and TypeScript environments, making it a reliable choice for handling HTTP response logic.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import and use various utilities to retrieve status codes, names, descriptions, and check code categories.

import { OK, NOT_FOUND, isSuccessCode, getStatusName, getStatusDescription, getNotFound, getStatusCode, CLIENT_ERROR_CODES } from 'http-response-status-code';

console.log('OK status code:', OK); // 200
console.log('Not Found status code:', NOT_FOUND); // 404

const status200Name = getStatusName(OK);
console.log('Name for 200:', status200Name); // OK

const status404Description = getStatusDescription(NOT_FOUND);
console.log('Description for 404:', status404Description); // Not Found

const nameForNotFound = getNotFound().name;
console.log('Name from getNotFound():', nameForNotFound); // Not Found

const codeForOK = getStatusCode('OK');
console.log('Code for "OK":', codeForOK); // 200

console.log('Is 200 a success code?', isSuccessCode(OK)); // true
console.log('Is 404 a success code?', isSuccessCode(NOT_FOUND)); // false

console.log('First 5 client error codes:', CLIENT_ERROR_CODES.slice(0, 5)); // [400, 401, 402, 403, 404]

view raw JSON →