JSPM

  • Created
  • Published
  • Downloads 14034
  • Score
    100M100P100Q139002F
  • License MIT

HTTP Request snippet generator for *most* languages

Package Exports

  • @readme/httpsnippet
  • @readme/httpsnippet/src/helpers/code-builder

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@readme/httpsnippet) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

HTTP Snippet version License

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 companion service: APIembed

Build

Installation

npm install --save @readme/httpsnippet

Usage

HTTPSnippet(source)

source

Required Type: object

Name of conversion target

const HTTPSnippet = require('httpsnippet');

const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'http://mockbin.com/request'
});

convert(target [, options])

target

Required Type: string

Name of conversion target

options

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'
}));

convert(target [, client, options])

target

Required Type: string

Name of conversion target

client

Type: string

Name of conversion target client library

options

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'));

addTarget(target)

target

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);

addTargetClient(target, client)

target

Required Type: string

Name of conversion target

client

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);

Documentation

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.

Differences from kong/httpsnippet

The main difference between this library and the upstream httpsnippet library are:

  • This targets Node 10+
  • Does not ship with a CLI component

License

MIT © Kong