Git Product home page Git Product logo

zunda-pixel / httpsnippet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from readmeio/httpsnippet

0.0 0.0 0.0 2.89 MB

HTTP Request snippet generator for many languages & libraries

License: MIT License

Shell 2.46% JavaScript 16.60% Ruby 1.37% Python 0.82% C 1.69% PHP 6.39% Objective-C 6.57% Java 4.98% OCaml 1.29% Smalltalk 0.01% Clojure 0.85% R 1.03% Go 1.97% C# 3.33% PowerShell 1.95% Kotlin 1.26% TypeScript 43.74% Swift 2.66% Dockerfile 1.05%

httpsnippet's Introduction

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 ReadMe.

Build

Installation

npm install --save @readme/httpsnippet

Usage

HTTPSnippet(input [, options])

input

Required Type: object

The HAR request object to generate a snippet for.

import { HTTPSnippet } from '@readme/httpsnippet';

const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'https://httpbin.org/anything',
});

options

Type: object

Available options:

  • harIsAlreadyEncoded (boolean): In the event of you supplying a source 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.

convert(target [, options])

target

Required Type: string

Name of conversion target

options

Type: object

Target options, see wiki for details

import { HTTPSnippet } from '@readme/httpsnippet';

const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'https://httpbin.org/anything',
});

// 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

import { HTTPSnippet } from '@readme/httpsnippet';

const snippet = new HTTPSnippet({
  method: 'GET',
  url: 'https://httpbin.org/anything',
});

// 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.

import { customLanguageTarget } from '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.

import { customClient } from 'httpsnippet-for-my-node-http-client';
HTTPSnippet.addTargetClient('node', customClient);

addClientPlugin(plugin)

Plugin

Required Type: object

The client plugin to install.

addClientPlugin({
  target: 'node',
  client: {
    info: {
      key: 'custom',
      title: 'Custom HTTP library',
      link: 'https://example.com',
      description: 'A custom HTTP library',
      extname: '.custom',
    },
    convert: () => {
      return 'This was generated from a custom client.';
    },
  },
});

The above example will create a new custom client snippet generator for the node target.

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

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 an options argument for an harIsAlreadyEncoded 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 on go:native, node:native, ruby:native, and shell:curl as we don't want snippets generated for our users to bypass SSL certificate verification.
  • Includes a full plugin system, #addClientPlugin, for quick installation of a target client.
  • 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 JS fetch target as well.
    • request
      • Does not provide query string parameters in a params argument due to complexities with query encoding.
  • PHP
    • guzzle
      • Snippets have require_once('vendor/autoload.php'); prefixed at the top.
  • 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.

License

MIT © Kong

httpsnippet's People

Contributors

erunion avatar dependabot[bot] avatar thibaultcha avatar reynolek avatar darrenjennings avatar therebelrobot avatar llimllib avatar greenkeeper[bot] avatar kanadgupta avatar jeffyongtaotang avatar zunda-pixel avatar tggreene avatar rohit-gohri avatar gkoberger avatar gschier avatar jpadilla avatar jgiovaresco avatar dashron avatar shashiranjan84 avatar develohpanda avatar wtetsu avatar seanghay avatar karol-maciaszek avatar lottamus avatar sonicaghi avatar atvaark avatar amolgupta avatar anthonycats avatar windard avatar jonasholbech avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.