{"id":16393,"library":"httpsnippet","title":"HTTP Request Snippet Generator","description":"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.","status":"active","version":"3.0.10","language":"javascript","source_language":"en","source_url":"https://github.com/Kong/httpsnippet","tags":["javascript","api","clojure","crystal","csharp","curl","go","har","http","typescript"],"install":[{"cmd":"npm install httpsnippet","lang":"bash","label":"npm"},{"cmd":"yarn add httpsnippet","lang":"bash","label":"yarn"},{"cmd":"pnpm add httpsnippet","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const HTTPSnippet = require('httpsnippet')","symbol":"HTTPSnippet","correct":"import { HTTPSnippet } from 'httpsnippet'"},{"note":"HTTPSnippet is a named export, not a default export.","wrong":"import HTTPSnippet from 'httpsnippet'","symbol":"HTTPSnippet","correct":"import { HTTPSnippet } from 'httpsnippet'"},{"note":"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.","wrong":"import { HarRequest } from 'httpsnippet'","symbol":"HarRequest","correct":"import type { HarRequest } from 'httpsnippet/dist/src/har'"}],"quickstart":{"code":"import { HTTPSnippet } from 'httpsnippet';\n\nconst harRequest = {\n  method: 'POST',\n  url: 'https://api.example.com/users',\n  headers: [\n    { name: 'Content-Type', value: 'application/json' },\n    { name: 'Authorization', value: `Bearer ${process.env.API_KEY ?? ''}` }\n  ],\n  postData: {\n    mimeType: 'application/json',\n    text: JSON.stringify({ name: 'Jane Doe', email: 'jane.doe@example.com' })\n  }\n};\n\nconst snippet = new HTTPSnippet(harRequest);\n\n// Generate a JavaScript fetch snippet\nconst jsFetchCode = snippet.convert('javascript', 'fetch');\nconsole.log('---- JavaScript (Fetch) Snippet ----');\nconsole.log(jsFetchCode);\n\n// Generate a cURL snippet\nconst curlCode = snippet.convert('shell', 'curl');\nconsole.log('\\n---- cURL Snippet ----');\nconsole.log(curlCode);\n\n// Generate a Python Requests snippet\nconst pythonRequestsCode = snippet.convert('python', 'requests');\nconsole.log('\\n---- Python (Requests) Snippet ----');\nconsole.log(pythonRequestsCode);","lang":"typescript","description":"Demonstrates how to instantiate HTTPSnippet with a HAR request object and generate code snippets for JavaScript (fetch), cURL, and Python (Requests)."},"warnings":[{"fix":"Ensure your Node.js environment is at least version 10 or higher. For current versions, use Node.js >=20.","message":"Version 2.0.0 dropped support for Node.js versions older than 10. Running on older environments will lead to runtime errors.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your Node.js runtime to version 20 or newer to ensure compatibility.","message":"Starting 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.","severity":"breaking","affected_versions":">=3.0.4"},{"fix":"Upgrade to `httpsnippet` version 3.0.9 or newer to resolve `window` object access errors in SSR contexts.","message":"Earlier 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`.","severity":"gotcha","affected_versions":"<3.0.9"},{"fix":"Keep `httpsnippet` updated to the latest stable release (e.g., `npm update httpsnippet` or `yarn upgrade httpsnippet`).","message":"The 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Consult the official documentation or source code for a list of supported targets and clients to ensure correct usage.","message":"The `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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Update `httpsnippet` to version 3.0.9 or newer to fix SSR compatibility issues.","cause":"Attempting to use `httpsnippet` in an SSR environment with an older version that accesses browser-specific globals.","error":"ReferenceError: window is not defined"},{"fix":"Use ESM `import` syntax: `import { HTTPSnippet } from 'httpsnippet';`.","cause":"Trying to use `require()` to import `httpsnippet` in an ES Module project where `require` is not available or explicitly disallowed.","error":"ERR_REQUIRE_ESM"},{"fix":"Ensure you are using the named export `HTTPSnippet`: `import { HTTPSnippet } from 'httpsnippet'; const snippet = new HTTPSnippet(har);`","cause":"Attempting to instantiate `httpsnippet` using a default import or incorrect named import.","error":"TypeError: httpsnippet is not a constructor"},{"fix":"Upgrade your Node.js environment to version 20 or higher (e.g., using `nvm install 20` and `nvm use 20`).","cause":"Running the `httpsnippet` package on a Node.js runtime version older than 20.","error":"The package 'httpsnippet' requires Node.js version \"^20\"."}],"ecosystem":"npm"}