HTTP Request Snippet Generator

3.0.10 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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);

view raw JSON →