Registry / http-networking / httpsnippet-lite

httpsnippet-lite

JSON →
library3.0.5jsnpmunverified

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-lite
INSTALL
IMPORT
SIG · HTTPSNIPPET-LITE
H
httpsnippet-lite
http-networkingjavascriptv3.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HTTPSnippet
import { HTTPSnippet } from 'httpsnippet-lite';
const HTTPSnippet = require('httpsnippet-lite');
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`.
HarRequest
import type { HarRequest } from 'httpsnippet-lite';
import { HarRequest } from 'httpsnippet-lite';
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.
addTarget
import { addTarget } from 'httpsnippet-lite';
const { addTarget } = require('httpsnippet-lite');
Used for extending the library's functionality by registering custom code generation targets. Follows the same import guidance as `HTTPSnippet`.

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.

import { HTTPSnippet } from 'httpsnippet-lite'; const snippet = new HTTPSnippet({ method: 'GET', url: 'http://mockbin.com/request', headers: [ { name: 'Accept', value: 'application/json' } ], queryString: [ { name: 'foo', value: 'bar' } ] }); const options = { indent: '\t' }; const output = await snippet.convert('shell', 'curl', options); console.log(output); /* Expected output: curl -X GET 'http://mockbin.com/request?foo=bar' \ -H 'Accept: application/json' */
Debug
Known issues
breakingThe `convert()` method is asynchronous and returns a Promise. Failing to `await` its result will lead to unhandled promise rejections or incorrect output.
fix
Always use `await snippet.convert(...)` or handle the Promise explicitly with `.then()` and `.catch()`.
affects: >=3.0.0
gotchaHTTPSnippet-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.
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.
affects: >=3.0.0
gotchaThis 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.
fix
Consult the `httpsnippet-lite` README for a detailed list of differences if you are familiar with `Kong/httpsnippet`.
affects: >=3.0.0
breakingThis 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.
fix
Ensure your project's Node.js environment is version `14.13.0` or higher.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: httpsnippet_lite_1.HTTPSnippet is not a constructor
Attempting to use CommonJS `require` syntax or incorrect destructuring for an ESM-focused library, especially in TypeScript projects or modern Node.js environments.
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.
(node:...) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'convert' of undefined
Forgetting to `await` the asynchronous `snippet.convert()` method, leading to `convert` being called on an unresolved Promise.
fix
Always `await` the result of `snippet.convert(...)`. For example: `const output = await snippet.convert('shell', 'curl', options);`
Error: Invalid HAR format: Headers property must be an array
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.
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.
Upgrade
Version history
3.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
httpsnippet-lite — npm install httpsnippet-lite · libregistry