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.
npm install httpsnippet-liteVerified import paths — ran on the pinned version, not inferred.
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.
Always use `await snippet.convert(...)` or handle the Promise explicitly with `.then()` and `.catch()`.
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.
Consult the `httpsnippet-lite` README for a detailed list of differences if you are familiar with `Kong/httpsnippet`.
Ensure your project's Node.js environment is version `14.13.0` or higher.
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.Always `await` the result of `snippet.convert(...)`. For example: `const output = await snippet.convert('shell', 'curl', options);`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.
No dependency data recorded yet.