npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@httptoolkit/httpsnippet

v2.1.7

Published

HTTP request snippet generator for *most* languages

Downloads

212

Readme

@httptoolkit/HTTPSnippet Build Status Available on NPM

Part of HTTP Toolkit: powerful tools for building, testing & debugging HTTP(S)

Httpsnippet is an 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!

This library relies on the popular HAR format to import data and describe HTTP calls.

This is a fork of Kong's (previous Mashape's) httpsnippet library, which appears to no longer be maintained. This version is in active production use in HTTP Toolkit.

Install

# to use in cli
npm install --global @httptoolkit/httpsnippet

# to use as a module
npm install --save @httptoolkit/httpsnippet

Usage


  Usage: httpsnippet [options] <files ...>

  Options:

    -h, --help                output usage information
    -V, --version             output the version number
    -t, --target <target>     target output
    -c, --client [client]     target client library
    -o, --output <directory>  write output to directory
    -x, --extra [{"optionKey": "optionValue"}]  provide extra options for the target/client
Example

process single file: example.json in HAR Request Object format, or full HAR log format:

httpsnippet example.json --target node --client unirest --output ./snippets
$ tree snippets
snippets/
└── example.js

process multiple files:

httpsnippet ./*.json --target node --client request --output ./snippets
$ tree snippets/
snippets/
├── endpoint-1.js
├── endpoint-2.js
└── endpoint-3.js

provide extra options:

httpsnippet example.json --target http --output ./snippets -x '{"autoHost": false, "autoContentLength": false}'

API

HTTPSnippet(source)

source

Required Type: object

Name of conversion target

var HTTPSnippet = require('httpsnippet');

var 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 target docs for details

var HTTPSnippet = require('httpsnippet');

var 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 target docs for details

var HTTPSnippet = require('httpsnippet');

var 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 target docs.

Bugs and feature requests

Have a bug or a feature request? Please first read the issue guidelines and search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

For info on creating new conversion targets, please review this guideline

Moreover, if your pull request contains JavaScript patches or features, you must include relevant unit tests.

Editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at http://editorconfig.org.

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, this project is maintained under the Semantic Versioning guidelines. Sometimes we screw up, but we'll adhere to these rules whenever possible.

Releases will be numbered with the following format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backward compatibility bumps the major while resetting minor and patch
  • New additions without breaking backward compatibility bumps the minor while resetting the patch
  • Bug fixes and misc changes bumps only the patch

For more information on SemVer, please visit http://semver.org/.