{"id":16411,"library":"know-your-http-well","title":"HTTP Specification Reference Data","description":"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.","status":"active","version":"0.5.0","language":"javascript","source_language":"en","source_url":"git://github.com/andreineculau/know-your-http-well","tags":["javascript","http","rfc","json"],"install":[{"cmd":"npm install know-your-http-well","lang":"bash","label":"npm"},{"cmd":"yarn add know-your-http-well","lang":"bash","label":"yarn"},{"cmd":"pnpm add know-your-http-well","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is a CommonJS module. For ESM, use 'import * as httpWell from \"know-your-http-well\";' and access properties like 'httpWell.statusPhrasesToCodes'.","wrong":"import httpWell from 'know-your-http-well';","symbol":"httpWell","correct":"const httpWell = require('know-your-http-well');"},{"note":"Named imports from this CommonJS module directly are not supported without explicit interop configuration (e.g., in a bundler or 'type: module' with Node.js loaders).","wrong":"import { statusPhrasesToCodes } from 'know-your-http-well';","symbol":"statusPhrasesToCodes","correct":"const { statusPhrasesToCodes } = require('know-your-http-well');"},{"note":"As a CommonJS module, direct named imports (`import { ... } from 'pkg'`) are typically not functional. Use object destructuring with `require` or an aliased star import for ESM.","wrong":"import { statusCodesToPhrases } from 'know-your-http-well';","symbol":"statusCodesToPhrases","correct":"const { statusCodesToPhrases } = require('know-your-http-well');"}],"quickstart":{"code":"const httpWell = require('know-your-http-well');\nconst statusWell = httpWell.statusPhrasesToCodes;\nconst phraseWell = httpWell.statusCodesToPhrases;\n\n// Example: Server-side usage\n// In a hypothetical Express-like response handler:\n// res.statusCode = statusWell.NOT_FOUND;\n// console.log(`Set status to ${statusWell.NOT_FOUND}`);\n\n// Example: Client-side or common logic\nconst responseStatusCode = 404; // Simulate a response status\n\nif (responseStatusCode !== statusWell.OK) {\n    // Log 'Request returned 404 Not Found'\n    console.log('Request returned ' + responseStatusCode + ' ' + phraseWell[responseStatusCode]);\n}\n// Expected output: Request returned 404 Not Found","lang":"javascript","description":"Demonstrates importing the package using CommonJS and accessing HTTP status code utilities for both numerical codes and their corresponding phrases."},"warnings":[{"fix":"For ESM, use `import * as httpWell from 'know-your-http-well';` and access properties as `httpWell.statusPhrasesToCodes`. Alternatively, ensure your build setup correctly handles CommonJS interoperability.","message":"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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consult the changelog for each new version to understand any structural changes to the exported data objects, especially if you rely on specific keys or formats.","message":"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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"For 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);`.","cause":"Attempting to use `require()` in an ECMAScript Module (ESM) context without proper configuration or a `createRequire` helper.","error":"TypeError: require is not a function"},{"fix":"Ensure 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.","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.","error":"TypeError: Cannot read properties of undefined (reading 'NOT_FOUND')"}],"ecosystem":"npm"}