{"id":17689,"library":"http-constants-ts","title":"HTTP Constants for TypeScript","description":"The `http-constants-ts` library provides a comprehensive collection of standardized and commonly used non-standard HTTP constants, including headers, MIME types, tracking statuses, HTTP methods, content encodings, CSP directives and sources, HTTP response codes, and Cache-Control instructions. Currently stable at version 1.0.8, its release cadence is typically slow, reflecting the stable nature of HTTP specifications, with updates primarily driven by new RFCs or significant industry changes. A key differentiator is its TypeScript-first design, offering strong type safety and predictable access patterns through structured objects like `Headers.STRICT_TRANSPORT_SECURITY` or `MimeTypes.Application.JSON`. It ensures consistency by normalizing constant values: headers are capitalized (e.g., `Strict-Transport-Security`), MIME types, content encodings, and cache-control instructions are lowercase (e.g., `application/json`, `deflate`, `max-age`), and HTTP methods are uppercase (e.g., `POST`), reducing the chance of runtime errors from 'magic strings'.","status":"active","version":"1.0.8","language":"javascript","source_language":"en","source_url":"https://github.com/iDschepe/http-constants-ts","tags":["javascript","http headers","headers","mime-types","standard","tracking status","list of headers","list of mime-types","http methods","typescript"],"install":[{"cmd":"npm install http-constants-ts","lang":"bash","label":"npm"},{"cmd":"yarn add http-constants-ts","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-constants-ts","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Use named imports for all top-level constant groups. CommonJS `require` is not the primary usage pattern for this TypeScript-first library.","wrong":"const Headers = require('http-constants-ts').Headers;","symbol":"Headers","correct":"import { Headers } from 'http-constants-ts';"},{"note":"The library exports multiple named constant groups; there is no default export. Direct import of nested properties like `import { Application } from 'http-constants-ts/MimeTypes';` is not supported.","wrong":"import MimeTypes from 'http-constants-ts';","symbol":"MimeTypes","correct":"import { MimeTypes } from 'http-constants-ts';"},{"note":"Individual response codes like `OK` are nested properties of `ResponseCodes` (e.g., `ResponseCodes.OK`), not direct top-level exports.","wrong":"import { OK } from 'http-constants-ts/ResponseCodes';","symbol":"ResponseCodes","correct":"import { ResponseCodes } from 'http-constants-ts';"}],"quickstart":{"code":"import { Headers, MimeTypes, ResponseCodes, Methods, CSPD } from 'http-constants-ts';\n\nconsole.log(\"Common HTTP Headers:\");\nconsole.log(`Content-Type: ${Headers.CONTENT_TYPE}`);\nconsole.log(`Authorization: ${Headers.AUTHORIZATION}`);\n\nconsole.log(\"\\nPopular MIME Types:\");\nconsole.log(`JSON: ${MimeTypes.Application.JSON}`);\nconsole.log(`PNG: ${MimeTypes.Image.PNG}`);\nconsole.log(`HTML: ${MimeTypes.Text.HTML}`);\n\nconsole.log(\"\\nHTTP Response Codes:\");\nconsole.log(`OK: ${ResponseCodes.OK} - ${ResponseCodes[ResponseCodes.OK]}`);\nconsole.log(`Not Found: ${ResponseCodes.NOT_FOUND} - ${ResponseCodes[ResponseCodes.NOT_FOUND]}`);\nconsole.log(`I'm a Teapot: ${ResponseCodes.I_AM_A_TEAPOT}`);\n\nconsole.log(\"\\nHTTP Methods:\");\nconsole.log(`GET: ${Methods.GET}`);\nconsole.log(`POST: ${Methods.POST}`);\n\nconsole.log(\"\\nCSP Directives:\");\nconsole.log(`Script Source: ${CSPD.SCRIPT_SRC}`);\nconsole.log(`Default Source: ${CSPD.DEFAULT_SRC}`);\n","lang":"typescript","description":"Demonstrates importing and using various HTTP constants like headers, MIME types, response codes, and methods, showing how to access their structured values in a type-safe manner."},"warnings":[{"fix":"Always refer to the library's internal key names as documented or inferred by TypeScript's intellisense (e.g., `Headers.CONTENT_TYPE`, not `Headers['Content-Type']`).","message":"Constant keys for headers, MIME types, and other values are normalized within the library. Hyphens are typically replaced by underscores, and casing follows specific rules (e.g., `Strict-Transport-Security` becomes `Headers.STRICT_TRANSPORT_SECURITY`).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware of the expected casing when using the constant values in contexts that are case-sensitive. The library provides the correct string literal for each constant.","message":"The string values of constants are strictly case-normalized: all headers are capitalized (e.g., `Content-Type`), MIME types and content encodings are lowercase (e.g., `application/json`), and methods are uppercase (e.g., `GET`).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer `import ... from 'http-constants-ts'` syntax. Ensure your project's `tsconfig.json` and `package.json` are configured for modern module resolution (e.g., `\"type\": \"module\"` in `package.json`, `\"module\": \"esnext\"` in `tsconfig.json`).","message":"This library is designed for ESM (ECMAScript Modules) usage with TypeScript. While it may transpile to CommonJS, using `require()` directly might lead to issues or require specific TypeScript/bundler configurations.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Access constants using the library's predefined keys, which typically convert hyphens to underscores and use uppercase for names (e.g., `Headers.CONTENT_TYPE` for `Content-Type`).","cause":"Attempting to access a constant using its raw HTTP string or incorrect casing/format instead of the library's normalized, uppercase, underscore-separated key.","error":"Property 'content-type' does not exist on type 'typeof Headers'. Did you mean 'CONTENT_TYPE'?"},{"fix":"Use ESM `import` statements: `import { Headers } from 'http-constants-ts';`. Ensure your `package.json` has `\"type\": \"module\"` if running directly in Node.js, or your bundler is configured correctly.","cause":"Trying to use CommonJS `require()` syntax in an environment configured for ECMAScript Modules (ESM).","error":"TypeError: require is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}