Registry / http-networking / httpsnippet

httpsnippet

JSON →
library3.0.10jsnpmunverified

httpsnippet is a JavaScript/TypeScript library that generates code snippets for HTTP requests across a wide array of programming languages and libraries from an HTTP Archive (HAR) object. It supports numerous targets, including cURL, JavaScript (Fetch, XMLHttpRequest, Axios), Node.js (request, Axios), Python (Requests), Java (OkHttp, Unirest), C#, Go, PHP, and more. The current stable version is 3.0.10, and the project maintains an active release cadence, frequently addressing dependency vulnerabilities, fixing bugs, and expanding support for new languages and clients. It is primarily used for developer tools, API documentation, and code generation, allowing users to easily translate network requests into runnable code examples.

npm install httpsnippet
INSTALL
IMPORT
SIG · HTTPSNIPPET
H
httpsnippet
http-networkingjavascriptv3.0.10
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'
const HTTPSnippet = require('httpsnippet')
The library is primarily designed for ESM environments with TypeScript types. While CommonJS might work in some setups, `require` is generally discouraged since Node.js v20+ is required.
HTTPSnippet
import { HTTPSnippet } from 'httpsnippet'
import HTTPSnippet from 'httpsnippet'
HTTPSnippet is a named export, not a default export.
HarRequest
import type { HarRequest } from 'httpsnippet/dist/src/har'
import { HarRequest } from 'httpsnippet'
Type definitions for HAR objects are available but might require importing from a specific path if not re-exported at the top level, or relying on ambient types.

Demonstrates how to instantiate HTTPSnippet with a HAR request object and generate code snippets for JavaScript (fetch), cURL, and Python (Requests).

import { HTTPSnippet } from 'httpsnippet'; const harRequest = { method: 'POST', url: 'https://api.example.com/users', headers: [ { name: 'Content-Type', value: 'application/json' }, { name: 'Authorization', value: `Bearer ${process.env.API_KEY ?? ''}` } ], postData: { mimeType: 'application/json', text: JSON.stringify({ name: 'Jane Doe', email: 'jane.doe@example.com' }) } }; const snippet = new HTTPSnippet(harRequest); // Generate a JavaScript fetch snippet const jsFetchCode = snippet.convert('javascript', 'fetch'); console.log('---- JavaScript (Fetch) Snippet ----'); console.log(jsFetchCode); // Generate a cURL snippet const curlCode = snippet.convert('shell', 'curl'); console.log('\n---- cURL Snippet ----'); console.log(curlCode); // Generate a Python Requests snippet const pythonRequestsCode = snippet.convert('python', 'requests'); console.log('\n---- Python (Requests) Snippet ----'); console.log(pythonRequestsCode);
Debug
Known issues
breakingVersion 2.0.0 dropped support for Node.js versions older than 10. Running on older environments will lead to runtime errors.
fix
Ensure your Node.js environment is at least version 10 or higher. For current versions, use Node.js >=20.
affects: >=2.0.0
breakingStarting with version 3.0.4, the library officially requires Node.js version 20 or higher. Running on earlier versions (e.g., Node.js 18) will cause an engine incompatibility error.
fix
Upgrade your Node.js runtime to version 20 or newer to ensure compatibility.
affects: >=3.0.4
gotchaEarlier versions of `httpsnippet` (prior to v3.0.9) had issues when used in Server-Side Rendering (SSR) environments due to direct access to the `window` object, particularly when handling `form-data`.
fix
Upgrade to `httpsnippet` version 3.0.9 or newer to resolve `window` object access errors in SSR contexts.
affects: <3.0.9
gotchaThe package frequently addresses critical and high-severity vulnerabilities in its dependencies. It is crucial to regularly update to the latest patch versions to mitigate security risks.
fix
Keep `httpsnippet` updated to the latest stable release (e.g., `npm update httpsnippet` or `yarn upgrade httpsnippet`).
affects: all
gotchaThe `convert` method expects specific `target` and `client` string identifiers (e.g., 'javascript', 'fetch'). Using incorrect or unsupported identifiers will result in a 'Target not found' or similar error.
fix
Consult the official documentation or source code for a list of supported targets and clients to ensure correct usage.
affects: all
Errors
Common errors & fixes
ReferenceError: window is not defined
Attempting to use `httpsnippet` in an SSR environment with an older version that accesses browser-specific globals.
fix
Update `httpsnippet` to version 3.0.9 or newer to fix SSR compatibility issues.
ERR_REQUIRE_ESM
Trying to use `require()` to import `httpsnippet` in an ES Module project where `require` is not available or explicitly disallowed.
fix
Use ESM `import` syntax: `import { HTTPSnippet } from 'httpsnippet';`.
TypeError: httpsnippet is not a constructor
Attempting to instantiate `httpsnippet` using a default import or incorrect named import.
fix
Ensure you are using the named export `HTTPSnippet`: `import { HTTPSnippet } from 'httpsnippet'; const snippet = new HTTPSnippet(har);`
The package 'httpsnippet' requires Node.js version "^20".
Running the `httpsnippet` package on a Node.js runtime version older than 20.
fix
Upgrade your Node.js environment to version 20 or higher (e.g., using `nvm install 20` and `nvm use 20`).
Upgrade
Version history
3.0.10latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
httpsnippet — npm install httpsnippet · libregistry