http-converter
@johnhenry/http-converter is a modern, browser-compatible HTTP format
converter. It transforms between HTTP strings, HAR (HTTP Archive), cURL
commands, and Fetch API calls — bidirectionally, with auto-detection of
which format a given input is.
Provenance: adopted into the
@johnhenrynpm scope — the unscopedhttp-convertername is held by an unrelated, empty package from another author, so this is this library’s first real npm release, not a re-publish. Version restarts at0.0.0per the family’s scope-adoption convention (a new address is a new era), independent of the library’s actual maturity: 103 tests and a real bug-fix history predate the scope move — see the CHANGELOG for the fixes that shipped alongside it (a corrupting cURL tokenizer, HAR entries that crashed on spec-legal optional fields, CRLF bodies mangled on round-trip, and more).
- Browser-first: no Node.js dependencies, works in any modern browser
- Tree-shakeable: import only what you need, via subpath exports
- Bidirectional conversions: convert between any supported format
- TypeScript support: full type definitions included
- Auto-detection: automatically identifies format types
- Native API support: works with
Request/Responseobjects
Install
Section titled “Install”npm install @johnhenry/http-converterQuick example
Section titled “Quick example”import * as http from '@johnhenry/http-converter';
// Parse HTTP stringconst request = http.string.parse(`GET /api HTTP/1.1Host: example.com
`);
// Convert to cURL (fromRequest is async)const curl = await http.curl.fromRequest(request);console.log(curl);// curl 'https://example.com/api' -H 'host: example.com'
// Convert to HAR (fromRequest is async)const harEntry = await http.har.fromRequest(request);
// Convert to Fetch (fromRequest is async)const { url, options } = await http.fetch.fromRequest(request);const response = await fetch(url, options);Every fromRequest/fromResponse/stringify* function is async — they
must support native Request/Response inputs, which require awaiting
.text().
The pages here
Section titled “The pages here”- API — the
string,har,curl,fetch,body, andrandommodules, plus utilities and the full exports table - TypeScript — using the library’s type
definitions, including native
Request/Responsetyping
Browser support
Section titled “Browser support”This library uses modern JavaScript features: ES Modules, the
TextEncoder API, the URL API, and the Headers API (for Fetch
conversions). Request/Response support is optional. Supported in all
modern browsers (Chrome 61+, Firefox 60+, Safari 10.1+, Edge 79+).
License
Section titled “License”MIT