http-z is a focused JavaScript and TypeScript library for parsing and building HTTP messages (requests and responses) in strict accordance with RFC 7230. It provides distinct functions to convert raw HTTP strings into a structured model and to serialize a model back into a raw message string. The current stable version is 8.1.1, indicating ongoing maintenance and development. A key differentiator for http-z is its zero-dependency design, which contributes to a minimal footprint, making it suitable for environments where bundle size is critical. It operates seamlessly across both Node.js (requiring Node.js >=18) and modern web browser environments. This library is ideal for developers needing low-level interaction with HTTP message serialization and deserialization, offering a robust, RFC-compliant alternative to higher-level HTTP client or server frameworks by concentrating solely on the message structure.
npm install http-zVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a raw HTTP GET request, inspecting its structured model, modifying the model to represent a POST request, and then rebuilding the raw HTTP message from the modified model.
Upgrade your Node.js environment to version 18 or newer to ensure compatibility.
Ensure input messages are strictly RFC 7230 compliant. Use robust error handling around `parse` calls to catch and log specific parsing failures.
Manually update the `Content-Length` header in the message model to match the byte length of the `body` string, especially after modifying the body content.
Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`) and use `import { parse, build } from 'http-z'` syntax. If staying in CommonJS, you might need a transpiler or a dynamic import `import('http-z').then(({ parse, build }) => ...)`.Use the correct named import syntax: `import { parse, build } from 'http-z'`. Verify your Node.js environment supports ESM or use a bundler/transpiler if targeting older environments.Review the `rawMessage` string for common HTTP formatting issues: incorrect line endings (must be `\r\n`), missing blank line between headers and body, malformed status lines or headers, or invalid characters. Ensure all parts of the HTTP message are correctly structured.
Verify that `parse` is imported as a named export: `import { parse } from 'http-z'`. Avoid `import httpz from 'http-z'` as there is no default export for the main functions.No dependency data recorded yet.