HTTPSnippet-lite

3.0.5 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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'
*/

view raw JSON →