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.
npm install http-status-codeVerified import paths — ran on the pinned version, not inferred.
Demonstrates retrieving HTTP status messages for various codes, including protocol-specific lookups, and fetching a list of all codes for a given protocol.
Always check the return value of `getMessage` to ensure it's not 'Unknown' if you need to rely on a specific message being present. Consider falling back to a generic message or logging a warning if 'Unknown' is returned.
If using TypeScript or a modern bundler, `import HTTPStatusCode from 'http-status-code';` should work. For strict CommonJS environments, use `const HTTPStatusCode = require('http-status-code');`.Refer to the documentation or source for exact protocol string names. Common valid values are 'HTTP/1.0', 'HTTP/1.1', 'HTTP/2'.
Ensure `HTTPStatusCode` is correctly imported: `const HTTPStatusCode = require('http-status-code');` in CommonJS or `import HTTPStatusCode from 'http-status-code';` in ESM.Access `getMessage` as a method of the default import: `import HTTPStatusCode from 'http-status-code'; HTTPStatusCode.getMessage(200);`
No dependency data recorded yet.