Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

httpsnippet

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpsnippet

HTTP Request snippet generator for *most* languages

  • 1.4.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
54K
decreased by-4.56%
Maintainers
1
Weekly downloads
 
Created
Source

HTTP Snippet version License

HTTP Request snippet generator for most languages.

Relies on the popular HAR format to import data and describe HTTP calls.

Build Status Downloads Code Climate Coverage Status Dependencies

Table of contents

Targets

currently the following output targets are supported:

Installation

install from source or through npm:

# to use in cli
npm install --global httpsnippet

# to use as a module
npm install httpsnippet

Usage

CLI

Usage: httpsnippet [options] <file>

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
  -n, --output-name <name>  output file name
Example

process single file (assumes HAR Request Object Format):

EXAMPLE: my-api-endpoint.json
{
  "method": "POST",
  "url": "http://mockbin.com/request",
  "httpVersion": "HTTP/1.1",
  "queryString": [
    { "name": "foo", "value": "bar" },
    { "name": "foo", "value": "baz" },
    { "name": "baz", "value": "abc" }
  ],
  "headers": [
    { "name": "Accept", "value": "text/plain" },
    { "name": "Content-Type", "value": "application/json" },
    { "name": "X-Foo-Bar", "value": "Baz" }
  ],
  "cookies":  [
    { "name": "foo", "value": "bar" },
    { "name": "bar", "value": "baz" }
  ],
  "postData": {
    "mimeType": "application/json",
    "text": "{\"foo\": \"bar\"}"
  }
}
httpsnippet my-api-endpoint.json --target php --output ./snippets
$ tree snippets
snippets/
└── my-api-endpoint.php

process multiple files:

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

Module

var httpsnippet = require('httpsnippet');

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

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

// generate nodeJS output
console.log(snippet.convert('node'));

// generate PHP output
console.log(snippet.convert('php', 'curl'));

Documentation

At the heart of this module is the HAR Request object 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.

Output Targets

output targets are simple modules that expose a constructor (which handles the transformation) and a meta info property.

module.exports = function (opts) {
  // optionally process `opts` object for target specific configuration
  // 
  // process `this.source` object
  // 
  // return processed output as string
};

module.exports.info = {
  key: 'curl',
  title: 'cURL',
  link: 'http://curl.haxx.se/',
  description: 'curl is a command line tool and library for transferring data with URL syntax',
  extname: '.sh'
};

Target Options

cURL

OptionDefaultDescription
shortfalseuse short form of cURL CLI options
indent line break & indent output value, set to false to disable line breaks

Go

OptionDefaultDescription
errorCheckingfalseadd error checking for request, response and body
printBodytrueinclude code to print the body as a string
timeout-1sets a request timeout in seconds (requires go 1.3+)

HTTPie

OptionDefaultDescription
bodyfalseonly the response body is printed
headersfalseonly the response headers are printed
verbosefalseprint the whole HTTP exchange (request and response)
printfalseselects parts of the HTTP exchange, e.g. --print=Hh (see httpie docs)
certfalseuse a client side certificate (see httpie docs)
verifyfalseserver SSL certificate verification (see httpie docs)
prettyfalsesyntax highlighting (see httpie docs)
stylefalsesyntax highlighting (see httpie docs)
timeoutfalseoverwrite the default 30s timeout
shortfalseuse short form of cURL CLI options
indent line break & indent output value, set to false to disable line breaks

Wget

OptionDefaultDescription
shortfalseuse short form of cURL CLI options
indent line break & indent output value, set to false to disable line breaks
verbosefalseby default, --quiet is always used, unless verbose is set to true

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.

More over, 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/.

License

Licensed under The MIT License.

FAQs

Package last updated on 12 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc