# @readme/httpsnippet

> HTTP Request snippet generator for *most* languages

Latest version **11.4.1** (published 2026-10-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @readme/httpsnippet
pnpm add @readme/httpsnippet
yarn add @readme/httpsnippet
bun add @readme/httpsnippet
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 11.4.1 |
| Published | 2026-10-05 |
| First published | 2020-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 3 |
| Unpacked size | 755.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | gkoberger, domharrington, mjcuva, jonursenbach, rafegoldberg, darrenyong |
| Keywords | api, clojure, crystal, csharp, curl, go, har, http, httpie, httr, java, javascript, jquery, kotlin, objc, objective-c, ocaml, php, python, requests, ruby, rust, shell, snippet, swift, xhr, xmlhttprequest |

## Links

- npm: https://www.npmjs.com/package/@readme/httpsnippet
- Repository: https://github.com/readmeio/httpsnippet
- Issues: https://github.com/readmeio/httpsnippet/issues
- npm.io page: https://npm.io/package/@readme/httpsnippet

## Dependencies (3)

- [qs](https://npm.io/package/qs.md) ^6.15.0
- [type-fest](https://npm.io/package/type-fest.md) ^5.5.0
- [stringify-object](https://npm.io/package/stringify-object.md) ^3.3.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 11.4.1 (latest) — 2026-10-05
- 11.4.0 — 2026-07-27
- 11.3.2 — 2026-07-03
- 11.3.1 — 2026-06-25
- 11.3.0 — 2026-06-16
- 11.2.0 — 2026-06-10
- 11.1.0 — 2026-02-24
- 11.0.0 — 2024-09-23
- 10.1.1 — 2024-09-23
- 10.1.0 — 2024-09-05
- 10.0.5 — 2024-04-29
- 10.0.4 — 2024-04-12
- 10.0.3 — 2024-04-12
- 10.0.2 — 2024-04-11
- 10.0.1 — 2024-04-10
- … 55 more at https://npm.io/package/@readme/httpsnippet/versions

## README

# HTTPSnippet

> HTTP Request snippet generator for _many_ languages & tools including: `cURL`, `HTTPie`, `Javascript`, `Node`, `C`, `Java`, `PHP`, `Objective-C`, `Swift`, `Python`, `Ruby`, `Rust`, `C#`, `Go`, `OCaml` and [more](https://github.com/Kong/httpsnippet/wiki/Targets)!

Relies on the popular [HAR](http://www.softwareishard.com/blog/har-12-spec/#request) format to import data and describe HTTP calls.

See it in action on [ReadMe](https://docs.readme.com/reference/getopenroles).

[![Build](https://github.com/readmeio/httpsnippet/workflows/CI/badge.svg)](https://github.com/readmeio/httpsnippet)

## Installation

```shell
npm install --save @readme/httpsnippet
```

## Usage

### HTTPSnippet(input [, options])

#### input

_Required_ Type: `object`

The [HAR](http://www.softwareishard.com/blog/har-12-spec/#request) request object to generate a snippet for.

```ts
import { HTTPSnippet } from '@readme/httpsnippet';

const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'https://httpbin.org/anything',
});
```

#### options

Type: `object`

Available options:

- `harIsAlreadyEncoded` (`boolean`): In the event of you supplying a `source` HAR that already contains escaped data (query and cookie parameters)strings, this allows you to disable automatic encoding of those parameters to prevent them from being double-escaped.

### convert(target [, options])

#### target

_Required_ Type: `string`

Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)

#### options

Type: `object`

Target options, _see [wiki](https://github.com/Kong/httpsnippet/wiki/Targets) for details_

```ts
import { HTTPSnippet } from '@readme/httpsnippet';

const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'https://httpbin.org/anything',
});

// generate Node.js: Native output
console.log(snippet.convert('node'));

// generate Node.js: Native output, indent with tabs
console.log(
  snippet.convert('node', {
    indent: '\t',
  }),
);
```

### convert(target [, client, options])

#### Target

_Required_ Type: `string`

Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)

#### Client

Type: `string`

Name of conversion target [client library](https://github.com/Kong/httpsnippet/wiki/Targets)

#### Options

Type: `object`

Target options, _see [wiki](https://github.com/Kong/httpsnippet/wiki/Targets) for details_

```ts
import { HTTPSnippet } from '@readme/httpsnippet';

const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'https://httpbin.org/anything',
});

// generate Shell: cURL output
console.log(
  snippet.convert('shell', 'curl', {
    indent: '\t',
  }),
);

// generate Node.js: Axios output
console.log(snippet.convert('node', 'axios'));
```

### addTarget(target)

#### target

_Required_ Type: `object`

Representation of a [conversion target](https://github.com/Kong/httpsnippet/wiki/Creating-Targets). Can use this to use targets that are not officially supported.

```ts
import { customLanguageTarget } from 'httpsnippet-for-my-lang';
HTTPSnippet.addTarget(customLanguageTarget);
```

### addTargetClient(target, client)

#### Target

_Required_ Type: `string`

Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)

#### Client

_Required_ Type: `object`

Representation of a [conversion target client](https://github.com/Kong/httpsnippet/wiki/Creating-Targets). Can use this to use target clients that are not officially supported.

```ts
import { customClient } from 'httpsnippet-for-my-node-http-client';
HTTPSnippet.addTargetClient('node', customClient);
```

### addClientPlugin(plugin)

#### Plugin

_Required_ Type: `object`

The client plugin to install.

```ts
addClientPlugin({
  target: 'node',
  client: {
    info: {
      key: 'custom',
      title: 'Custom HTTP library',
      link: 'https://example.com',
      description: 'A custom HTTP library',
      extname: '.custom',
    },
    convert: () => {
      return 'This was generated from a custom client.';
    },
  },
});
```

The above example will create a new `custom` client snippet generator for the `node` target.

## Documentation

At the heart of this module is the [HAR Format](http://www.softwareishard.com/blog/har-12-spec/#request) as the HTTP request description format, please review some of the sample JSON HAR Request objects in [test fixtures](/test/fixtures/requests), or read the [HAR Docs](http://www.softwareishard.com/blog/har-12-spec/#request) for more details.

For detailed information on each target, please review the [wiki](https://github.com/Kong/httpsnippet/wiki).

## Differences from `kong/httpsnippet`

There are some major differences between this library and the [httpsnippet](https://github.com/Kong/httpsnippet) upstream:

- Includes a full integration test suite for a handful of clients and targets.
- Does not ship with a CLI component.
- Does not do any HAR schema validation. It's just assumed that the HAR you're supplying to the library is already valid.
- The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs.
  - We added this because all HARs that we interact with already have this data escaped and this option prevents them from being double encoded, thus corrupting the data.
- Does not support the `insecureSkipVerify` option on `go:native`, `node:native`, `ruby:native`, and `shell:curl` as we don't want snippets generated for our users to bypass SSL certificate verification.
- Includes a full plugin system, `#addClientPlugin`, for quick installation of a target client.
- Node
  - `fetch`
    - Body payloads are treated as an object literal and wrapped within `JSON.stringify()`. We do this to keep those targets looking nicer with those kinds of payloads. This also applies to the JS `fetch` target as well.
  - `request`
    - Does not provide query string parameters in a `params` argument due to complexities with query encoding.
- PHP
  - `guzzle`
    - Snippets have `require_once('vendor/autoload.php');` prefixed at the top.
- Python
  - `python3`
    - Does not ship this client due to its incompatibility with being able to support file uploads.
  - `requests`
    - Does not provide query string parameters in a `params` argument due to complexities with query encoding.

## License

[MIT](LICENSE) &copy; [Kong](https://konghq.com)

[license-url]: https://github.com/Kong/httpsnippet/blob/master/LICENSE
[npm-url]: https://www.npmjs.com/package/@readme/httpsnippet
[npm-license]: https://img.shields.io/npm/l/@readme/httpsnippet.svg?style=flat-square
[npm-version]: https://img.shields.io/npm/v/@readme/httpsnippet.svg?style=flat-square

---
_Source: https://npm.io/package/@readme/httpsnippet · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
