{"id":16061,"library":"http-codex","title":"HTTP Codex","description":"http-codex is a lightweight JavaScript/TypeScript library providing constants for standard HTTP status codes and methods, inspired by and closely mirroring the API of Go's `net/http` package. It is currently at version `0.6.6` and appears to be actively maintained, being part of a larger monorepo with recent updates to other packages. The library differentiates itself by its explicit goal to align with Go's `http` package conventions and its focus on bundle size, offering granular imports (e.g., `http-codex/status` or `http-codex/method`) to minimize the loaded code. It includes helper functions like `isNullBodyStatus` for common HTTP response handling patterns. While no strict release cadence is stated, its presence in an active monorepo suggests ongoing development and support.","status":"active","version":"0.6.6","language":"javascript","source_language":"en","source_url":"https://github.com/jahands/workers-packages","tags":["javascript","http status codes","http methods","http","status codes","methods","typescript"],"install":[{"cmd":"npm install http-codex","lang":"bash","label":"npm"},{"cmd":"yarn add http-codex","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-codex","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Main entry point provides all features including `statusText()` helper.","wrong":"const httpStatus = require('http-codex')","symbol":"httpStatus","correct":"import { httpStatus } from 'http-codex'"},{"note":"For smallest bundle size, import methods directly from 'http-codex/method'. The main export also includes it.","wrong":"import { httpMethod } from 'http-codex'","symbol":"httpMethod","correct":"import { httpMethod } from 'http-codex/method'"},{"note":"This helper is part of the main `http-codex` export, not the status-only subpath.","wrong":"import { isNullBodyStatus } from 'http-codex/status'","symbol":"isNullBodyStatus","correct":"import { isNullBodyStatus } from 'http-codex'"}],"quickstart":{"code":"import { httpMethod, httpStatus, isNullBodyStatus } from 'http-codex';\n\n// Example: Creating a simple HTTP response\nconst createResponse = (body: string | null, statusCode: number) => {\n  const statusText = httpStatus.text(statusCode);\n  return new Response(body, {\n    status: statusCode,\n    statusText: statusText,\n    headers: { 'Content-Type': 'text/plain' }\n  });\n};\n\nconst successResponse = createResponse('Operation successful!', httpStatus.OK); // Status 200, \"OK\"\nconst notFoundResponse = createResponse('Resource not found', httpStatus.NOT_FOUND); // Status 404, \"Not Found\"\nconst noContentResponse = createResponse(null, httpStatus.NO_CONTENT); // Status 204, no body\n\nconsole.log('Success Response:', successResponse.status, successResponse.statusText);\nconsole.log('Not Found Response:', notFoundResponse.status, notFoundResponse.statusText);\nconsole.log('No Content Response:', noContentResponse.status, noContentResponse.statusText);\n\n// Example: Using HTTP methods\nconst currentMethod = httpMethod.GET; // 'GET'\nconst allowedMethods = [httpMethod.GET, httpMethod.POST, httpMethod.PUT];\n\nif (!allowedMethods.includes(currentMethod)) {\n  console.error(`Method ${currentMethod} is not allowed.`);\n} else {\n  console.log(`Method ${currentMethod} is allowed.`);\n}\n\n// Example: Handling null body statuses\nconst mockFetchResult = { status: httpStatus.NO_CONTENT, body: 'unwanted content' };\nconst finalBody = isNullBodyStatus(mockFetchResult.status) ? null : mockFetchResult.body;\nconsole.log('Final body after null body check:', finalBody);","lang":"typescript","description":"This quickstart demonstrates how to use `http-codex` to construct `Response` objects with proper status codes and texts, use HTTP method constants, and apply the `isNullBodyStatus` helper function."},"warnings":[{"fix":"Ensure you import `httpStatus` from `'http-codex'` if you need the `statusText()` method, or implement status text handling manually if using the smaller `'http-codex/status'` import.","message":"The `statusText()` helper function is only available when importing `httpStatus` from the main `http-codex` package entry point. It is *not* exported when importing `httpStatus` specifically from `http-codex/status` to reduce bundle size.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use `import { httpMethod } from 'http-codex/method'` or `import { httpStatus } from 'http-codex/status'` for targeted imports, then import other helpers like `isNullBodyStatus` from the main package if needed.","message":"For optimal bundle size, avoid importing the entire `http-codex` package if you only need HTTP methods or status codes. Importing directly from `http-codex/method` or `http-codex/status` significantly reduces the payload.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Refer to the `http-codex` documentation and examples, keeping in mind its Go-inspired design principles, rather than assuming direct parity with other JavaScript HTTP libraries.","message":"This library is designed to mimic Go's `net/http` package API. Developers accustomed to Node.js-specific HTTP libraries or other JavaScript HTTP utilities might find the API patterns slightly different.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change the import to `import { httpStatus } from 'http-codex'` to access the `statusText()` helper, or manually map status codes to text if `http-codex/status` is specifically required for bundle size.","cause":"Attempting to call `text()` on `httpStatus` after importing it from `'http-codex/status'`.","error":"TypeError: httpStatus.text is not a function"},{"fix":"Ensure your project is configured for ES Modules (e.g., `\"type\": \"module\"` in `package.json`) and use `import { ... } from 'http-codex'` syntax. If a CommonJS environment is strictly required, consider using a bundler like Webpack or Rollup to transpile.","cause":"Attempting to `require('http-codex')` in a CommonJS environment or mixing CJS and ESM import styles.","error":"ERR_MODULE_NOT_FOUND: Cannot find module 'http-codex' from '...' or SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}