Registry / http-networking / http-core-constants

http-core-constants

JSON →
library1.3.0jsnpmunverified

The `http-core-constants` library provides a JavaScript/TypeScript port of standard HTTP constants, encompassing headers, status codes, and request methods. These constants are derived directly from the `org.apache.httpcomponents:httpcore` Java library, offering a familiar set of values for developers migrating from Java environments or seeking a standardized set of HTTP definitions. The current stable version is 1.3.0, released in February 2020. The package has seen no updates since then, indicating an abandoned status. A key differentiator is its inclusion of `SC_` prefixed status codes (mirroring Apache's Java library) alongside non-prefixed, more readable alternatives. It primarily serves to eliminate 'magic strings' in HTTP-related code, promoting type safety and maintainability in TypeScript projects by exposing these constants as enums.

npm install http-core-constants
INSTALL
IMPORT
SIG · HTTP-CORE-CONSTANT
H
http-core-constants
http-networkingjavascriptv1.3.0
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.

HttpHeaders
import { HttpHeaders } from 'http-core-constants';
const HttpHeaders = require('http-core-constants').HttpHeaders;
Since v1.3.0, HttpHeaders is an enum; use named import.
HttpStatus
import { HttpStatus } from 'http-core-constants';
const HttpStatus = require('http-core-constants').HttpStatus;
Since v1.3.0, HttpStatus is an enum; use named import. Both `SC_OK` and `OK` forms are available.
HttpRequestMethod
import { HttpRequestMethod } from 'http-core-constants';
const HttpRequestMethod = require('http-core-constants').HttpRequestMethod;
Since v1.3.0, HttpRequestMethod is an enum; use named import.

Demonstrates importing and using various HTTP constants for headers, status codes, and request methods.

import { HttpHeaders, HttpStatus, HttpRequestMethod } from 'http-core-constants'; console.log(`Accept header: ${HttpHeaders.ACCEPT}`); console.log(`OK status code (SC_OK): ${HttpStatus.SC_OK}`); console.log(`OK status code (OK): ${HttpStatus.OK}`); console.log(`HTTP GET method: ${HttpRequestMethod.GET}`); // Example using status code in a mock response class MockHttpResponse { status: HttpStatus; constructor(status: HttpStatus) { this.status = status; } send(body: string) { console.log(`Sending response with status ${this.status}: ${body}`); } } const response = new MockHttpResponse(HttpStatus.OK); response.send('Operation successful!');
Debug
Known issues
breakingVersion 1.3.0 converted all constant modules (HttpHeaders, HttpStatus, HttpRequestMethod) from plain objects to TypeScript enum declarations. This change can impact consumers relying on object-like behaviors such as iteration over properties or dynamic property access, and may alter runtime types for some JavaScript environments.
fix
Review code that interacts with these constants, especially if performing operations typically applied to plain objects. Ensure correct enum usage in TypeScript, and be aware of potential runtime differences in JavaScript if reflection or dynamic property listing was previously used.
affects: >=1.3.0
gotchaThe `http-core-constants` package has not been updated since February 2020. This indicates the package is likely abandoned and will not receive updates for new HTTP standards, bug fixes, or security patches. Consider using more actively maintained alternatives for critical projects.
fix
Evaluate alternative HTTP constant libraries such as `http-status-codes` or `@poppanator/http-constants` which are actively maintained and support more recent HTTP specifications and features.
affects: >=1.3.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'ACCEPT')
This typically occurs when attempting to access a named export from a CommonJS `require` statement without explicitly destructuring it, or when using an incorrect import path.
fix
For ESM, ensure named imports are used: `import { HttpHeaders } from 'http-core-constants';`. For CommonJS (if using an older version or transpiled code), ensure destructuring: `const { HttpHeaders } = require('http-core-constants');`.
TypeError: HttpHeaders is not a constructor
The constants (e.g., `HttpHeaders`, `HttpStatus`) are exported as enums (or plain objects in older versions) and are not intended to be instantiated with `new`.
fix
Access constants directly as properties of the imported enum/object, for example: `HttpHeaders.ACCEPT` or `HttpStatus.SC_OK`.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
http-core-constants — npm install http-core-constants · libregistry