{"id":16392,"library":"httpsnippet-lite","title":"HTTPSnippet-lite","description":"HTTPSnippet-lite is a JavaScript and TypeScript library designed to generate HTTP request code snippets across a wide array of programming languages and tools, including cURL, JavaScript (Fetch, Axios), Node.js (native, request), Python, Go, C#, Java, and more. It functions by taking a JSON object conforming to the HTTP Archive (HAR) format's HarRequest or HarEntry specification as input and converting it into executable code. Currently at version 3.0.5, the package is in active production use, offering a stable solution for developers needing versatile HTTP snippet generation. As a maintained fork of the original Kong/httpsnippet, `httpsnippet-lite` distinguishes itself by having no reliance on Node.js core modules, providing a leaner footprint, and explicitly marking its `convert` method as asynchronous. It does *not* perform HAR input validation, assuming the provided HAR is well-formed, which is a key difference from its predecessor.","status":"active","version":"3.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/P0lip/httpsnippet","tags":["javascript","api","clojure","csharp","curl","go","har","http","httpie","typescript"],"install":[{"cmd":"npm install httpsnippet-lite","lang":"bash","label":"npm"},{"cmd":"yarn add httpsnippet-lite","lang":"bash","label":"yarn"},{"cmd":"pnpm add httpsnippet-lite","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library is primarily designed for ESM/TypeScript environments. While dual packaging might be available, `require` can lead to interop issues depending on your environment and bundler configuration. It's recommended to use ESM `import`.","wrong":"const HTTPSnippet = require('httpsnippet-lite');","symbol":"HTTPSnippet","correct":"import { HTTPSnippet } from 'httpsnippet-lite';"},{"note":"HarRequest is a TypeScript interface/type. Use `import type` for type-only imports to prevent accidental runtime imports and optimize bundle size, especially crucial with bundlers.","wrong":"import { HarRequest } from 'httpsnippet-lite';","symbol":"HarRequest","correct":"import type { HarRequest } from 'httpsnippet-lite';"},{"note":"Used for extending the library's functionality by registering custom code generation targets. Follows the same import guidance as `HTTPSnippet`.","wrong":"const { addTarget } = require('httpsnippet-lite');","symbol":"addTarget","correct":"import { addTarget } from 'httpsnippet-lite';"}],"quickstart":{"code":"import { HTTPSnippet } from 'httpsnippet-lite';\n\nconst snippet = new HTTPSnippet({\n  method: 'GET',\n  url: 'http://mockbin.com/request',\n  headers: [\n    { name: 'Accept', value: 'application/json' }\n  ],\n  queryString: [\n    { name: 'foo', value: 'bar' }\n  ]\n});\n\nconst options = { indent: '\\t' };\nconst output = await snippet.convert('shell', 'curl', options);\n\nconsole.log(output);\n/* Expected output:\ncurl -X GET 'http://mockbin.com/request?foo=bar' \\\n\t-H 'Accept: application/json'\n*/","lang":"typescript","description":"This quickstart demonstrates how to instantiate `HTTPSnippet` with a basic HAR request object and then convert it into a cURL snippet using specific formatting options."},"warnings":[{"fix":"Always use `await snippet.convert(...)` or handle the Promise explicitly with `.then()` and `.catch()`.","message":"The `convert()` method is asynchronous and returns a Promise. Failing to `await` its result will lead to unhandled promise rejections or incorrect output.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Thoroughly validate your HAR input against the HAR 1.2 specification (or the corresponding TypeScript types like `har-format`) before passing it to `HTTPSnippet` to ensure correctness.","message":"HTTPSnippet-lite does *not* perform validation on the input HAR (HTTP Archive) object. It assumes the provided `HarRequest` or `HarEntry` is strictly compliant with the HAR specification. Providing malformed HAR data can lead to unexpected output or runtime errors without explicit warnings.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Consult the `httpsnippet-lite` README for a detailed list of differences if you are familiar with `Kong/httpsnippet`.","message":"This package (`httpsnippet-lite`) is a fork of the original `Kong/httpsnippet` and is independently maintained. Key differences include no reliance on Node.js core modules, the `convert()` method being async, and the absence of HAR validation. Users migrating from or accustomed to the original `httpsnippet` should review the documentation for behavioral changes and feature set differences.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Ensure your project's Node.js environment is version `14.13.0` or higher.","message":"This package specifies a Node.js engine requirement of `>=14.13`. Running the library on older Node.js versions may result in compatibility issues, runtime errors, or unexpected behavior.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Use ESM named imports: `import { HTTPSnippet } from 'httpsnippet-lite';`. If operating in a pure CommonJS environment, ensure your build setup correctly handles ESM interop or verify `httpsnippet-lite`'s CJS export behavior.","cause":"Attempting to use CommonJS `require` syntax or incorrect destructuring for an ESM-focused library, especially in TypeScript projects or modern Node.js environments.","error":"TypeError: httpsnippet_lite_1.HTTPSnippet is not a constructor"},{"fix":"Always `await` the result of `snippet.convert(...)`. For example: `const output = await snippet.convert('shell', 'curl', options);`","cause":"Forgetting to `await` the asynchronous `snippet.convert()` method, leading to `convert` being called on an unresolved Promise.","error":"(node:...) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'convert' of undefined"},{"fix":"Ensure your HAR input strictly adheres to the HAR specification. For `headers`, it must be an array of objects, each with `name` and `value` properties. Review HAR documentation for correct structure.","cause":"The input HAR object (e.g., `HarRequest` or `HarEntry`) contains malformed data, such as a non-array value for the `headers` property, which `httpsnippet-lite` does not validate.","error":"Error: Invalid HAR format: Headers property must be an array"}],"ecosystem":"npm"}