{"id":16379,"library":"http-enums","title":"HTTP Enums (Status, Methods, Headers)","description":"http-enums is a utility library providing standardized JavaScript and TypeScript enumerations for common HTTP concepts, including status codes, request methods, and frequently used request and response headers. As of version 1.0.5, last published approximately three years ago (around January 2020), it offers a straightforward and type-safe way to reference these constants, aiming to reduce the use of 'magic strings' in web development projects. Due to its static nature as a collection of constants, it generally does not require frequent updates; however, the lack of recent maintenance means it may not incorporate the latest HTTP specification changes or benefit from community-driven improvements. It differentiates itself by its singular focus on providing comprehensive HTTP enums, suitable for both client-side and server-side applications where explicit constant definitions enhance code clarity.","status":"abandoned","version":"1.0.5","language":"javascript","source_language":"en","source_url":"git@github.com:mafh612/http-utils","tags":["javascript","typescript"],"install":[{"cmd":"npm install http-enums","lang":"bash","label":"npm"},{"cmd":"yarn add http-enums","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-enums","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This library ships with TypeScript types and is primarily designed for ESM-style named imports. CommonJS `require` works but is not idiomatic.","wrong":"const HttpStatus = require('http-enums').HttpStatus;","symbol":"HttpStatus","correct":"import { HttpStatus } from 'http-enums';"},{"note":"Only named exports are provided for individual enum collections; default imports will fail.","wrong":"import HttpMethod from 'http-enums';","symbol":"HttpMethod","correct":"import { HttpMethod } from 'http-enums';"},{"note":"While `import * as HttpEnums from 'http-enums'` would import all exports, it's generally better practice to import specific symbols for clarity and tree-shaking.","wrong":"import * as HttpEnums from 'http-enums';","symbol":"HttpRequestHeaders, HttpResponseHeaders","correct":"import { HttpRequestHeaders, HttpResponseHeaders } from 'http-enums';"}],"quickstart":{"code":"import { HttpStatus, HttpMethod, HttpRequestHeaders, HttpResponseHeaders } from 'http-enums';\n\nfunction handleRequest(method: HttpMethod, status: HttpStatus, headers: Record<string, string>): void {\n  console.log(`Received ${method} request with status ${status}.`);\n\n  if (method === HttpMethod.GET) {\n    console.log('This is a GET request.');\n  }\n\n  if (status === HttpStatus.NOT_FOUND) {\n    console.log('Resource not found.');\n  }\n\n  if (headers[HttpRequestHeaders.ACCEPT_LANGUAGE] === 'en-US') {\n    console.log('Client prefers US English.');\n  }\n\n  console.log(`Setting Content-Type to: ${HttpResponseHeaders.CONTENT_TYPE_APPLICATION_JSON}`);\n}\n\nhandleRequest(HttpMethod.POST, HttpStatus.CREATED, { 'accept-language': 'en-US', [HttpRequestHeaders.CONTENT_TYPE]: 'application/json' });\nhandleRequest(HttpMethod.GET, HttpStatus.OK, { 'user-agent': 'MyBrowser/1.0' });\n","lang":"typescript","description":"Demonstrates importing various HTTP enumerations (status, method, request/response headers) and using their values in a TypeScript function."},"warnings":[{"fix":"For projects requiring the absolute latest HTTP specification accuracy or active maintenance, consider alternative, more recently updated HTTP utility libraries or defining custom enums.","message":"The `http-enums` package has not been updated in approximately three years (since January 2020). While HTTP standards are relatively stable, this means it may not include very recent additions or clarifications to HTTP status codes, methods, or headers. Consider this if working with cutting-edge HTTP specifications.","severity":"gotcha","affected_versions":">=1.0.5"},{"fix":"When comparing against actual HTTP header values, convert the incoming header key to lowercase: `const incomingHeaders = { 'Content-Type': 'application/json' }; if (incomingHeaders['content-type'] === 'application/json') { /* ... */ }`.","message":"Header names in HTTP are case-insensitive by standard, but JavaScript string comparisons are case-sensitive. While `HttpRequestHeaders` and `HttpResponseHeaders` provide canonical names, always normalize incoming header keys (e.g., to lowercase) before direct comparison if they come from external sources like `req.headers` in Node.js.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For CommonJS, it is generally safer to `const HttpEnums = require('http-enums');` and then access properties like `HttpEnums.HttpStatus`. However, for modern TypeScript/JavaScript projects, stick to `import { HttpStatus } from 'http-enums';`.","message":"Attempting to use `require` to import individual named exports directly (e.g., `const { HttpStatus } = require('http-enums');`) might lead to `undefined` or runtime errors in some CommonJS environments, especially if the package's `package.json` specifies `\"type\": \"module\"` or uses only ESM syntax internally.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using named imports correctly: `import { HttpMethod } from 'http-enums';`. If using CommonJS, verify the `require` statement loads the module correctly before accessing its properties.","cause":"Attempting to access an enum member (e.g., `HttpMethod.GET`) when the enum object itself (`HttpMethod`) was not correctly imported or is `undefined`.","error":"TypeError: Cannot read properties of undefined (reading 'GET')"},{"fix":"Double-check the available exports from the `http-enums` package. Common exports are `HttpStatus`, `HttpMethod`, `HttpRequestHeaders`, and `HttpResponseHeaders`. Ensure correct casing.","cause":"Trying to import an enum symbol that does not exist or has been renamed in the `http-enums` package.","error":"TS2305: Module '\"http-enums\"' has no exported member 'MyCustomEnum'."},{"fix":"Add the necessary import statement at the top of your file: `import { HttpStatus } from 'http-enums';`.","cause":"Using an enum like `HttpStatus` without first importing it into the current file scope.","error":"ReferenceError: HttpStatus is not defined"}],"ecosystem":"npm"}