Registry / http-networking / http-constants-ts

http-constants-ts

JSON →
library1.0.8jsnpmunverified

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'.

npm install http-constants-ts
INSTALL
IMPORT
SIG · HTTP-CONSTANTS-TS
H
http-constants-ts
http-networkingjavascriptv1.0.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Headers
import { Headers } from 'http-constants-ts';
const Headers = require('http-constants-ts').Headers;
Use named imports for all top-level constant groups. CommonJS `require` is not the primary usage pattern for this TypeScript-first library.
MimeTypes
import { MimeTypes } from 'http-constants-ts';
import MimeTypes from 'http-constants-ts';
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.
ResponseCodes
import { ResponseCodes } from 'http-constants-ts';
import { OK } from 'http-constants-ts/ResponseCodes';
Individual response codes like `OK` are nested properties of `ResponseCodes` (e.g., `ResponseCodes.OK`), not direct top-level exports.

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.

import { Headers, MimeTypes, ResponseCodes, Methods, CSPD } from 'http-constants-ts'; console.log("Common HTTP Headers:"); console.log(`Content-Type: ${Headers.CONTENT_TYPE}`); console.log(`Authorization: ${Headers.AUTHORIZATION}`); console.log("\nPopular MIME Types:"); console.log(`JSON: ${MimeTypes.Application.JSON}`); console.log(`PNG: ${MimeTypes.Image.PNG}`); console.log(`HTML: ${MimeTypes.Text.HTML}`); console.log("\nHTTP Response Codes:"); console.log(`OK: ${ResponseCodes.OK} - ${ResponseCodes[ResponseCodes.OK]}`); console.log(`Not Found: ${ResponseCodes.NOT_FOUND} - ${ResponseCodes[ResponseCodes.NOT_FOUND]}`); console.log(`I'm a Teapot: ${ResponseCodes.I_AM_A_TEAPOT}`); console.log("\nHTTP Methods:"); console.log(`GET: ${Methods.GET}`); console.log(`POST: ${Methods.POST}`); console.log("\nCSP Directives:"); console.log(`Script Source: ${CSPD.SCRIPT_SRC}`); console.log(`Default Source: ${CSPD.DEFAULT_SRC}`);
Debug
Known issues
gotchaConstant 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`).
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']`).
affects: >=1.0.0
gotchaThe 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`).
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.
affects: >=1.0.0
gotchaThis 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.
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`).
affects: >=1.0.0
Errors
Common errors & fixes
Property 'content-type' does not exist on type 'typeof Headers'. Did you mean 'CONTENT_TYPE'?
Attempting to access a constant using its raw HTTP string or incorrect casing/format instead of the library's normalized, uppercase, underscore-separated key.
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`).
TypeError: require is not a function
Trying to use CommonJS `require()` syntax in an environment configured for ECMAScript Modules (ESM).
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.
Upgrade
Version history
1.0.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
25
Amazon
1
OpenAI (training)
1
Resources
http-constants-ts — npm install http-constants-ts · libregistry