HTTP Status Code Utilities

2.1.0 · active · verified Tue Apr 21

The `http-status-code` package provides a straightforward, protocol-aware utility for retrieving human-readable messages associated with HTTP status codes. Currently at version 2.1.0, this library does not indicate a rapid release cadence, suggesting a stable, mature, and low-maintenance tool. Its primary differentiation lies in allowing developers to specify the HTTP protocol version (e.g., HTTP/1.0, HTTP/1.1, HTTP/2) when querying for a status message, ensuring accuracy for protocol-specific codes or messages. If no protocol is specified, it defaults to a comprehensive set. It's a simple, focused solution for translating numeric status codes into their standard descriptions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates retrieving HTTP status messages for various codes, including protocol-specific lookups, and fetching a list of all codes for a given protocol.

import HTTPStatusCode from 'http-status-code';

// Get the message for a common status code without specifying a protocol
console.log('HTTP 200 message:', HTTPStatusCode.getMessage(200));

// Get the message for a status code specific to HTTP/1.1
console.log('HTTP/1.1 429 message:', HTTPStatusCode.getMessage(429, 'HTTP/1.1'));

// Get the message for a status code that might differ or be unknown in a specific protocol
console.log('WEBDAV 429 message (example of unknown):', HTTPStatusCode.getMessage(429, 'WEBDAV'));

// Retrieve all status codes for a specific protocol
const http2Codes = HTTPStatusCode.getProtocolStatusCodes('HTTP/2');
console.log('\nHTTP/2 status codes (first 5):', Object.entries(http2Codes).slice(0, 5));

view raw JSON →