or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli-usage.mdcore-api.mdhelper-utilities.mdindex.mdtargets-and-clients.md
tile.json

index.mddocs/

HTTPSnippet

HTTPSnippet is a TypeScript library for generating HTTP request code snippets in multiple programming languages. It takes HTTP requests in HAR (HTTP Archive) format and converts them into executable code for 20+ language targets including cURL, JavaScript, Python, Java, Go, and many more.

Package Information

  • Package Name: httpsnippet
  • Package Type: npm
  • Language: TypeScript
  • Installation:
    npm install httpsnippet
  • CLI Installation:
    npm install -g httpsnippet

Core Imports

import { HTTPSnippet } from "httpsnippet";

For CommonJS:

const { HTTPSnippet } = require("httpsnippet");

Additional imports:

import { 
  availableTargets,
  addTarget, 
  addTargetClient,
  extname,
  isHarEntry,
  targets,
  CodeBuilder,
  escapeString,
  escapeForSingleQuotes,
  escapeForDoubleQuotes,
  escape,
  getHeader,
  getHeaderName,
  hasHeader,
  isMimeTypeJSON,
  quote,
  type HarRequest,
  type HarEntry,
  type Request,
  type RequestExtras
} from "httpsnippet";

Basic Usage

import { HTTPSnippet } from "httpsnippet";

// Create snippet from HAR request
const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'https://api.example.com/users',
  headers: [
    { name: 'accept', value: 'application/json' },
    { name: 'authorization', value: 'Bearer token123' }
  ]
});

// Convert to different languages
const curl = snippet.convert('shell', 'curl');
const javascript = snippet.convert('javascript', 'fetch');
const python = snippet.convert('python', 'requests');

console.log(curl);
// Output: curl --request GET --url 'https://api.example.com/users' ...

Architecture

HTTPSnippet is built around several key components:

  • HTTPSnippet Class: Main class that processes HAR requests and converts them to code snippets
  • Target System: Extensible architecture supporting 20+ programming languages (targets) with multiple library implementations (clients) per language
  • Helper Modules: Utilities for code building, string escaping, and header processing
  • CLI Interface: Command-line tool for batch processing and file output
  • Type System: Full TypeScript support with comprehensive type definitions for HAR format and all targets

Capabilities

Core Snippet Generation

Main functionality for converting HAR requests into executable code snippets across multiple programming languages.

class HTTPSnippet {
  constructor(input: HarEntry | HarRequest);
  convert(targetId: TargetId, clientId?: ClientId, options?: any): string | string[] | false;
}

function isHarEntry(value: any): value is HarEntry;

Core API

Language Targets and Clients

Access to all supported programming languages and their available library clients, plus functionality to extend with custom targets.

function availableTargets(): AvailableTarget[];
function addTarget(target: Target): void;
function addTargetClient(targetId: TargetId, client: Client): void;
function extname(targetId: TargetId): string;
const targets: Record<TargetId, Target>;

type TargetId = 'c' | 'clojure' | 'crystal' | 'csharp' | 'go' | 'http' | 'java' | 
  'javascript' | 'kotlin' | 'node' | 'objc' | 'ocaml' | 'php' | 'powershell' | 
  'python' | 'r' | 'ruby' | 'rust' | 'shell' | 'swift';

Targets and Clients

Helper Utilities

Code building utilities, string escaping functions, and header processing tools for building and extending HTTPSnippet functionality.

class CodeBuilder {
  constructor(options?: CodeBuilderOptions);
  push(line: string, indentationLevel?: number): void;
  join(): string;
}

function escapeString(rawValue: any, options?: EscapeOptions): string;
function getHeader<T>(headers: Record<string, T>, name: string): T | undefined;

Helper Utilities

CLI Interface

Command-line interface for processing HAR files and generating code snippets with file output support.

httpsnippet <harFile> --target <target> --client <client> --output <directory>

CLI Usage

Types

interface HarRequest {
  method: string;
  url: string;
  httpVersion?: string;
  headers?: Array<{name: string, value: string}>;
  queryString?: Array<{name: string, value: string}>;
  cookies?: Array<{name: string, value: string}>;
  postData?: {
    mimeType: string;
    text?: string;
    params?: Array<{name: string, value: string}>;
  };
}

interface HarEntry {
  log: {
    version: string;
    creator: { name: string; version: string };
    entries: Array<{ request: Partial<HarRequest> }>;
  };
}

interface AvailableTarget {
  key: TargetId;
  title: string;
  extname: string;
  default: string;
  clients: ClientInfo[];
}

interface ClientInfo {
  key: string;
  title: string;
  link: string;
  description: string;
}

interface RequestExtras {
  fullUrl: string;
  queryObj: Record<string, any>;
  headersObj: Record<string, string>;
  cookiesObj: Record<string, string>;
  allHeaders: Record<string, string>;
  uriObj: Record<string, any>;
  postData: Record<string, any>;
}

type Request = HarRequest & RequestExtras;