HTTP Request snippet generator for many languages & tools including:
cURL,HTTPie,Javascript,Node,C,Java,PHP,Objective-C,Swift,Python,Ruby,C#,Go,OCamland more!
Relies on the popular HAR format to import data and describe HTTP calls.
See it in action on companion service: APIembed
npm install --save @readme/httpsnippetRequired
Type: object
Name of conversion target
const HTTPSnippet = require('httpsnippet');
const snippet = new HTTPSnippet({
method: 'GET',
url: 'http://mockbin.com/request'
});Required
Type: string
Name of conversion target
Type: object
Target options, see wiki for details
const HTTPSnippet = require('httpsnippet');
const snippet = new HTTPSnippet({
method: 'GET',
url: 'http://mockbin.com/request'
});
// 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'
}));Required
Type: string
Name of conversion target
Type: string
Name of conversion target client library
Type: object
Target options, see wiki for details
const HTTPSnippet = require('httpsnippet');
const snippet = new HTTPSnippet({
method: 'GET',
url: 'http://mockbin.com/request'
});
// generate Shell: cURL output
console.log(snippet.convert('shell', 'curl', {
indent: '\t'
}));
// generate Node.js: Unirest output
console.log(snippet.convert('node', 'unirest'));Required
Type: object
Representation of a conversion target. Can use this to use targets that are not officially supported.
const customLanguageTarget = require('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.
const customClient = require('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.
The main difference between this library and the upstream httpsnippet library are:
- This targets Node 10+
- Does not ship with a CLI component
- Adds a
useObjectBodyoption to the node target. This option is a boolean flag that causes the request body to be rendered as an object literal wrapped inJSON.stringify. If disabled, it falls back to the original behavior of a stringified object body. This flag defaults to disabled.