@readme/httpsnippet 8.0.1 → 8.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,13 +16,13 @@ npm install --save @readme/httpsnippet
16
16
 
17
17
  ## Usage
18
18
 
19
- ### HTTPSnippet(source [, options])
19
+ ### HTTPSnippet(input [, options])
20
20
 
21
- #### source
21
+ #### input
22
22
 
23
23
  _Required_ Type: `object`
24
24
 
25
- Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)
25
+ The [HAR](http://www.softwareishard.com/blog/har-12-spec/#request) request object to generate a snippet for.
26
26
 
27
27
  ```ts
28
28
  import { HTTPSnippet } from 'httpsnippet';
@@ -128,13 +128,13 @@ HTTPSnippet.addTarget(customLanguageTarget);
128
128
 
129
129
  ### addTargetClient(target, client)
130
130
 
131
- ### Target
131
+ #### Target
132
132
 
133
133
  _Required_ Type: `string`
134
134
 
135
135
  Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)
136
136
 
137
- ### Client
137
+ #### Client
138
138
 
139
139
  _Required_ Type: `object`
140
140
 
@@ -145,6 +145,34 @@ import { customClient } from 'httpsnippet-for-my-node-http-client';
145
145
  HTTPSnippet.addTargetClient('node', customClient);
146
146
  ```
147
147
 
148
+ ### addClientPlugin(plugin)
149
+
150
+ #### Plugin
151
+
152
+ _Required_ Type: `object`
153
+
154
+ The client plugin to install.
155
+
156
+ ```ts
157
+ addClientPlugin({
158
+ target: 'node',
159
+ client: {
160
+ info: {
161
+ key: 'custom',
162
+ title: 'Custom HTTP library',
163
+ link: 'https://example.com',
164
+ description: 'A custom HTTP library',
165
+ extname: '.custom',
166
+ },
167
+ convert: () => {
168
+ return 'This was generated from a custom client.';
169
+ },
170
+ },
171
+ });
172
+ ```
173
+
174
+ The above example will create a new `custom` client snippet generator for the `node` target.
175
+
148
176
  ## Documentation
149
177
 
150
178
  At the heart of this module is the [HAR Format](http://www.softwareishard.com/blog/har-12-spec/#request) as the HTTP request description format, please review some of the sample JSON HAR Request objects in [test fixtures](/test/fixtures/requests), or read the [HAR Docs](http://www.softwareishard.com/blog/har-12-spec/#request) for more details.
@@ -161,6 +189,7 @@ There are some major differences between this library and the [httpsnippet](http
161
189
  - The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs.
162
190
  - 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.
163
191
  - 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.
192
+ - Includes a full plugin system, `#addClientPlugin`, for quick installation of a target client.
164
193
  - Node
165
194
  - `fetch`
166
195
  - 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.
@@ -431,7 +431,8 @@ var restsharp = {
431
431
  title: "RestSharp",
432
432
  link: "http://restsharp.org/",
433
433
  description: "Simple REST and HTTP API Client for .NET",
434
- extname: ".cs"
434
+ extname: ".cs",
435
+ installation: "dotnet add package RestSharp"
435
436
  },
436
437
  convert: ({ method, fullUrl, headersObj, cookies, postData, uriObj }) => {
437
438
  const { push, join } = new CodeBuilder();
@@ -843,7 +844,8 @@ var axios = {
843
844
  title: "Axios",
844
845
  link: "https://github.com/axios/axios",
845
846
  description: "Promise based HTTP client for the browser and node.js",
846
- extname: ".js"
847
+ extname: ".js",
848
+ installation: "npm install axios --save"
847
849
  },
848
850
  convert: ({ allHeaders, method, url, queryObj, postData }, options) => {
849
851
  const opts = {
@@ -1275,7 +1277,8 @@ var axios2 = {
1275
1277
  title: "Axios",
1276
1278
  link: "https://github.com/axios/axios",
1277
1279
  description: "Promise based HTTP client for the browser and node.js",
1278
- extname: ".cjs"
1280
+ extname: ".cjs",
1281
+ install: "npm install axios --save"
1279
1282
  },
1280
1283
  convert: ({ method, fullUrl, allHeaders, postData }, options) => {
1281
1284
  const opts = {
@@ -1337,7 +1340,8 @@ var fetch2 = {
1337
1340
  title: "Fetch",
1338
1341
  link: "https://github.com/bitinn/node-fetch",
1339
1342
  description: "Simplified HTTP node-fetch client",
1340
- extname: ".cjs"
1343
+ extname: ".cjs",
1344
+ installation: "npm install node-fetch@2 --save"
1341
1345
  },
1342
1346
  convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
1343
1347
  const opts = {
@@ -1511,7 +1515,8 @@ var request = {
1511
1515
  title: "Request",
1512
1516
  link: "https://github.com/request/request",
1513
1517
  description: "Simplified HTTP request client",
1514
- extname: ".cjs"
1518
+ extname: ".cjs",
1519
+ installation: "npm install request --save"
1515
1520
  },
1516
1521
  convert: ({ method, url, fullUrl, postData, headersObj, cookies }, options) => {
1517
1522
  const opts = {
@@ -1875,7 +1880,8 @@ var cohttp = {
1875
1880
  title: "CoHTTP",
1876
1881
  link: "https://github.com/mirage/ocaml-cohttp",
1877
1882
  description: "Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml",
1878
- extname: ".ml"
1883
+ extname: ".ml",
1884
+ installation: "opam install cohttp-lwt-unix cohttp-async"
1879
1885
  },
1880
1886
  convert: ({ fullUrl, allHeaders, postData, method }, options) => {
1881
1887
  const opts = {
@@ -2121,7 +2127,8 @@ var guzzle = {
2121
2127
  title: "Guzzle",
2122
2128
  link: "http://docs.guzzlephp.org/en/stable/",
2123
2129
  description: "PHP with Guzzle",
2124
- extname: ".php"
2130
+ extname: ".php",
2131
+ installation: "composer require guzzlehttp/guzzle"
2125
2132
  },
2126
2133
  convert: ({ postData, fullUrl, method, cookies, headersObj }, options) => {
2127
2134
  const opts = {
@@ -2546,7 +2553,8 @@ var requests = {
2546
2553
  title: "Requests",
2547
2554
  link: "http://docs.python-requests.org/en/latest/api/#requests.request",
2548
2555
  description: "Requests HTTP library",
2549
- extname: ".py"
2556
+ extname: ".py",
2557
+ installation: "python -m pip install requests"
2550
2558
  },
2551
2559
  convert: ({ fullUrl, postData, allHeaders, method }, options) => {
2552
2560
  const opts = {
@@ -3007,7 +3015,8 @@ var httpie = {
3007
3015
  title: "HTTPie",
3008
3016
  link: "http://httpie.org/",
3009
3017
  description: "a CLI, cURL-like tool for humans",
3010
- extname: ".sh"
3018
+ extname: ".sh",
3019
+ installation: "brew install httpie"
3011
3020
  },
3012
3021
  convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }, options) => {
3013
3022
  const opts = {
@@ -3425,6 +3434,9 @@ var isClient = (client) => {
3425
3434
  }
3426
3435
  return true;
3427
3436
  };
3437
+ var addClientPlugin = (plugin) => {
3438
+ addTargetClient(plugin.target, plugin.client);
3439
+ };
3428
3440
  var addTargetClient = (targetId, client) => {
3429
3441
  if (!isClient(client)) ;
3430
3442
  if (!Object.prototype.hasOwnProperty.call(targets, targetId)) {
@@ -3438,6 +3450,6 @@ var addTargetClient = (targetId, client) => {
3438
3450
  targets[targetId].clientsById[client.info.key] = client;
3439
3451
  };
3440
3452
 
3441
- export { addTarget, addTargetClient, getHeaderName, isClient, isTarget, targets };
3453
+ export { addClientPlugin, addTarget, addTargetClient, getHeaderName, isClient, isTarget, targets };
3442
3454
  //# sourceMappingURL=out.js.map
3443
- //# sourceMappingURL=chunk-IAWYVBVW.js.map
3455
+ //# sourceMappingURL=chunk-NPUBNYOA.js.map