HTTP Specification Reference Data
know-your-http-well is a JavaScript package that provides structured data for various HTTP specifications, including headers, media types, methods, relations, and status codes. It summarizes these elements and links directly to their respective RFCs and specifications. The current stable version is v0.6.0, with minor content updates driving recent releases. Its primary use case is to offer programmatic access to standardized HTTP information, such as converting status phrases to codes and vice-versa, making it useful for both server-side and client-side applications that need to interpret or generate HTTP messages correctly. The project serves as a reference data set, updated periodically with new RFCs and corrections, rather than offering complex runtime functionality or a rapid release cadence for API changes. Its key differentiator is providing this data in an easily consumable JSON and JavaScript format, directly referencing official specifications.
Common errors
-
TypeError: require is not a function
cause Attempting to use `require()` in an ECMAScript Module (ESM) context without proper configuration or a `createRequire` helper.fixFor ESM, change `const httpWell = require('know-your-http-well');` to `import * as httpWell from 'know-your-http-well';`. If you need CommonJS specifically in an ESM file, use `import { createRequire } from 'module'; const require = createRequire(import.meta.url);`. -
TypeError: Cannot read properties of undefined (reading 'NOT_FOUND')
cause This usually occurs if the `know-your-http-well` package was not correctly imported, or the `statusPhrasesToCodes` (aliased as `statusWell` in the quickstart) object itself is undefined or lacks the 'NOT_FOUND' property. This can happen with incorrect ESM imports.fixEnsure you are importing the package correctly, especially in ESM environments. Use `import * as httpWell from 'know-your-http-well';` then access `httpWell.statusPhrasesToCodes.NOT_FOUND`. Verify the exact case ('NOT_FOUND' vs 'NotFound') for status codes.
Warnings
- gotcha This package is distributed as a CommonJS module. When using it in an ECMAScript Module (ESM) environment (e.g., Node.js with 'type: module' or modern frontend builds), standard named imports (`import { Name } from 'pkg'`) will not work directly. You must use `import * as pkg from 'pkg';` or rely on bundler/runtime interop.
- gotcha The package primarily provides data via JavaScript objects. While the data is derived from RFCs, its structure (e.g., property names for status codes like `NOT_FOUND`) might evolve slightly between minor versions to reflect new specifications or corrections. Always test after updates.
Install
-
npm install know-your-http-well -
yarn add know-your-http-well -
pnpm add know-your-http-well
Imports
- httpWell
import httpWell from 'know-your-http-well';
const httpWell = require('know-your-http-well'); - statusPhrasesToCodes
import { statusPhrasesToCodes } from 'know-your-http-well';const { statusPhrasesToCodes } = require('know-your-http-well'); - statusCodesToPhrases
import { statusCodesToPhrases } from 'know-your-http-well';const { statusCodesToPhrases } = require('know-your-http-well');
Quickstart
const httpWell = require('know-your-http-well');
const statusWell = httpWell.statusPhrasesToCodes;
const phraseWell = httpWell.statusCodesToPhrases;
// Example: Server-side usage
// In a hypothetical Express-like response handler:
// res.statusCode = statusWell.NOT_FOUND;
// console.log(`Set status to ${statusWell.NOT_FOUND}`);
// Example: Client-side or common logic
const responseStatusCode = 404; // Simulate a response status
if (responseStatusCode !== statusWell.OK) {
// Log 'Request returned 404 Not Found'
console.log('Request returned ' + responseStatusCode + ' ' + phraseWell[responseStatusCode]);
}
// Expected output: Request returned 404 Not Found