{"id":16378,"library":"http-core-constants","title":"HTTP Core Constants Library","description":"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.","status":"abandoned","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/aquariuslt/http-core-constants","tags":["javascript","apache","http-components","http-core","constants"],"install":[{"cmd":"npm install http-core-constants","lang":"bash","label":"npm"},{"cmd":"yarn add http-core-constants","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-core-constants","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v1.3.0, HttpHeaders is an enum; use named import.","wrong":"const HttpHeaders = require('http-core-constants').HttpHeaders;","symbol":"HttpHeaders","correct":"import { HttpHeaders } from 'http-core-constants';"},{"note":"Since v1.3.0, HttpStatus is an enum; use named import. Both `SC_OK` and `OK` forms are available.","wrong":"const HttpStatus = require('http-core-constants').HttpStatus;","symbol":"HttpStatus","correct":"import { HttpStatus } from 'http-core-constants';"},{"note":"Since v1.3.0, HttpRequestMethod is an enum; use named import.","wrong":"const HttpRequestMethod = require('http-core-constants').HttpRequestMethod;","symbol":"HttpRequestMethod","correct":"import { HttpRequestMethod } from 'http-core-constants';"}],"quickstart":{"code":"import { HttpHeaders, HttpStatus, HttpRequestMethod } from 'http-core-constants';\n\nconsole.log(`Accept header: ${HttpHeaders.ACCEPT}`);\nconsole.log(`OK status code (SC_OK): ${HttpStatus.SC_OK}`);\nconsole.log(`OK status code (OK): ${HttpStatus.OK}`);\nconsole.log(`HTTP GET method: ${HttpRequestMethod.GET}`);\n\n// Example using status code in a mock response\nclass MockHttpResponse {\n    status: HttpStatus;\n    constructor(status: HttpStatus) {\n        this.status = status;\n    }\n    send(body: string) {\n        console.log(`Sending response with status ${this.status}: ${body}`);\n    }\n}\n\nconst response = new MockHttpResponse(HttpStatus.OK);\nresponse.send('Operation successful!');","lang":"typescript","description":"Demonstrates importing and using various HTTP constants for headers, status codes, and request methods."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=1.3.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.3.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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');`.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'ACCEPT')"},{"fix":"Access constants directly as properties of the imported enum/object, for example: `HttpHeaders.ACCEPT` or `HttpStatus.SC_OK`.","cause":"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`.","error":"TypeError: HttpHeaders is not a constructor"}],"ecosystem":"npm"}