httpsnippet 7.2.1
Install from the command line:
Learn more about npm packages
$ npm install @zuplo/httpsnippet@7.2.1
Install via package.json:
"@zuplo/httpsnippet": "7.2.1"
About this version
HTTP Request snippet generator for many languages & tools including:
cURL
,HTTPie
,Javascript
,Node
,C
,Java
,PHP
,Objective-C
,Swift
,Python
,Ruby
,C#
,Go
,OCaml
and more!
Relies on the popular HAR format to import data and describe HTTP calls.
See it in action on ReadMe.
npm install --save @readme/httpsnippet
Required Type: object
Name of conversion target
import { HTTPSnippet } from 'httpsnippet';
const snippet = new HTTPSnippet({
method: 'GET',
url: 'https://httpbin.org/anything',
});
Type: object
Available options:
-
harIsAlreadyEncoded
(boolean
): In the event of you supplying asource
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.
Required Type: string
Name of conversion target
Type: object
Target options, see wiki for details
import { HTTPSnippet } from 'httpsnippet';
const snippet = new HTTPSnippet({
method: 'GET',
url: 'httsp://httpbin.org/anything',
});
// generate Node.js: Native output
console.log(await snippet.convert('node'));
// generate Node.js: Native output, indent with tabs
console.log(
await snippet.convert('node', {
indent: '\t',
}),
);
Required Type: string
Name of conversion target
Type: string
Name of conversion target client library
Type: object
Target options, see wiki for details
import { HTTPSnippet } from 'httpsnippet';
const snippet = new HTTPSnippet({
method: 'GET',
url: 'https://httpbin.org/anything',
});
// generate Shell: cURL output
console.log(
await snippet.convert('shell', 'curl', {
indent: '\t',
}),
);
// generate Node.js: Unirest output
console.log(await snippet.convert('node', 'unirest'));
Required Type: object
Representation of a conversion target. Can use this to use targets that are not officially supported.
import { customLanguageTarget } from 'httpsnippet-for-my-lang';
HTTPSnippet.addTarget(customLanguageTarget);
Required Type: string
Name of conversion target
Required Type: object
Representation of a conversion target client. Can use this to use target clients that are not officially supported.
import { customClient } from 'httpsnippet-for-my-node-http-client';
HTTPSnippet.addTargetClient('node', customClient);
At the heart of this module is the HAR Format as the HTTP request description format, please review some of the sample JSON HAR Request objects in test fixtures, or read the HAR Docs for more details.
For detailed information on each target, please review the wiki.
There are some major differences between this library and the 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 anoptions
argument for anharIsAlreadyEncoded
option for disabling escaping 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 ongo:native
,node:native
,ruby:native
, andshell:curl
as we don't want snippets generated for our users to bypass SSL certificate verification. - 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 JSfetch
target as well.
- Body payloads are treated as an object literal and wrapped within
-
request
- Does not provide query string parameters in a
params
argument due to complexities with query encoding.
- Does not provide query string parameters in a
-
- PHP
-
guzzle
- Snippets have
require_once('vendor/autoload.php');
prefixed at the top.
- Snippets have
-
- 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.
- Does not provide query string parameters in a
-