• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Kong/httpsnippet: HTTP Request snippet generator for many languages & librar ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

Kong/httpsnippet

开源软件地址(OpenSource Url):

https://github.com/Kong/httpsnippet

开源编程语言(OpenSource Language):

TypeScript 44.6%

开源软件介绍(OpenSource 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 companion service: APIembed

Build Downloads

Install

# to use in cli
npm install --global httpsnippet

# to use as a module
npm install --save 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

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

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

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

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

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.

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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap