@readme/httpsnippet 3.1.3 → 4.0.2
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 +63 -62
- package/dist/package.json +86 -0
- package/dist/src/fixtures/customTarget.js +15 -0
- package/dist/src/fixtures/mimetypes.js +77 -0
- package/dist/src/fixtures/requests/application-form-encoded.js +69 -0
- package/dist/src/fixtures/requests/application-json.js +72 -0
- package/dist/src/fixtures/requests/cookies.js +51 -0
- package/dist/src/fixtures/requests/custom-method.js +41 -0
- package/dist/src/fixtures/requests/full.js +99 -0
- package/dist/src/fixtures/requests/headers.js +56 -0
- package/dist/src/fixtures/requests/http-insecure.js +45 -0
- package/dist/src/fixtures/requests/jsonObj-multiline.js +59 -0
- package/dist/src/fixtures/requests/jsonObj-null-value.js +61 -0
- package/dist/src/fixtures/requests/multipart-data.js +72 -0
- package/dist/src/fixtures/requests/multipart-file.js +65 -0
- package/dist/src/fixtures/requests/multipart-form-data-no-params.js +56 -0
- package/dist/src/fixtures/requests/multipart-form-data.js +64 -0
- package/dist/src/fixtures/requests/nested.js +64 -0
- package/dist/src/fixtures/requests/query-encoded.js +59 -0
- package/dist/src/fixtures/requests/query.js +64 -0
- package/dist/src/fixtures/requests/short.js +45 -0
- package/dist/src/fixtures/requests/text-plain.js +57 -0
- package/dist/src/fixtures/runCustomFixtures.js +77 -0
- package/dist/src/helpers/code-builder.js +91 -0
- package/dist/src/helpers/form-data.js +157 -0
- package/dist/src/helpers/har-validator.js +76 -0
- package/dist/src/helpers/headers.js +33 -0
- package/dist/src/helpers/reducer.js +19 -0
- package/dist/src/helpers/shell.js +20 -0
- package/dist/src/helpers/utils.js +21 -0
- package/dist/src/index.js +285 -0
- package/dist/src/targets/c/libcurl/client.js +43 -0
- package/dist/src/targets/c/target.js +15 -0
- package/dist/src/targets/clojure/clj_http/client.js +184 -0
- package/dist/src/targets/clojure/target.js +15 -0
- package/dist/src/targets/csharp/httpclient/client.js +162 -0
- package/dist/src/targets/csharp/restsharp/client.js +38 -0
- package/dist/src/targets/csharp/target.js +17 -0
- package/dist/src/targets/go/native/client.js +122 -0
- package/dist/src/targets/go/target.js +15 -0
- package/dist/src/targets/http/http1.1/client.js +79 -0
- package/dist/src/targets/http/target.js +15 -0
- package/dist/src/targets/java/asynchttp/client.js +53 -0
- package/dist/src/targets/java/nethttp/client.js +52 -0
- package/dist/src/targets/java/okhttp/client.js +79 -0
- package/dist/src/targets/java/target.js +21 -0
- package/dist/src/targets/java/unirest/client.js +53 -0
- package/dist/src/targets/javascript/axios/client.js +101 -0
- package/dist/src/targets/javascript/axios/fixtures/application-form-encoded.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/application-json.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/cookies.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/custom-method.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/full.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/headers.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/http-insecure.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-data.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-file.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/nested.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/query-encoded.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/query.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/short.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/text-plain.js +19 -0
- package/dist/src/targets/javascript/fetch/client.js +115 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-form-encoded.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-json.js +16 -0
- package/dist/src/targets/javascript/fetch/fixtures/cookies.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/custom-method.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/full.js +13 -0
- package/dist/src/targets/javascript/fetch/fixtures/headers.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/http-insecure.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-data.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-file.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/nested.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query-encoded.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/short.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/text-plain.js +5 -0
- package/dist/src/targets/javascript/jquery/client.js +93 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/full.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/headers.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-data.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-file.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
- package/dist/src/targets/javascript/target.js +21 -0
- package/dist/src/targets/javascript/xhr/client.js +90 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-form-encoded.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-json.js +31 -0
- package/dist/src/targets/javascript/xhr/fixtures/cookies.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/cors.js +10 -0
- package/dist/src/targets/javascript/xhr/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/full.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/headers.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/text-plain.js +12 -0
- package/dist/src/targets/kotlin/okhttp/client.js +79 -0
- package/dist/src/targets/kotlin/target.js +15 -0
- package/dist/src/targets/node/axios/client.js +87 -0
- package/dist/src/targets/node/axios/fixtures/application-form-encoded.js +19 -0
- package/dist/src/targets/node/axios/fixtures/application-json.js +22 -0
- package/dist/src/targets/node/axios/fixtures/cookies.js +14 -0
- package/dist/src/targets/node/axios/fixtures/custom-method.js +10 -0
- package/dist/src/targets/node/axios/fixtures/full.js +22 -0
- package/dist/src/targets/node/axios/fixtures/headers.js +14 -0
- package/dist/src/targets/node/axios/fixtures/http-insecure.js +10 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-file.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +14 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/nested.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query-encoded.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query.js +13 -0
- package/dist/src/targets/node/axios/fixtures/short.js +10 -0
- package/dist/src/targets/node/axios/fixtures/text-plain.js +15 -0
- package/dist/src/targets/node/fetch/client.js +149 -0
- package/dist/src/targets/node/fetch/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/fetch/fixtures/application-json.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/cookies.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/custom-method.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/full.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/headers.js +10 -0
- package/dist/src/targets/node/fetch/fixtures/http-insecure.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-multiline.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-null-value.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/nested.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query-encoded.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/short.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/text-plain.js +7 -0
- package/dist/src/targets/node/native/client.js +91 -0
- package/dist/src/targets/node/native/fixtures/application-form-encoded.js +24 -0
- package/dist/src/targets/node/native/fixtures/application-json.js +30 -0
- package/dist/src/targets/node/native/fixtures/cookies.js +22 -0
- package/dist/src/targets/node/native/fixtures/custom-method.js +20 -0
- package/dist/src/targets/node/native/fixtures/full.js +26 -0
- package/dist/src/targets/node/native/fixtures/headers.js +24 -0
- package/dist/src/targets/node/native/fixtures/http-insecure.js +20 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-multiline.js +23 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-null-value.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-file.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data-no-params.js +22 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/nested.js +20 -0
- package/dist/src/targets/node/native/fixtures/query-encoded.js +20 -0
- package/dist/src/targets/node/native/fixtures/query.js +20 -0
- package/dist/src/targets/node/native/fixtures/short.js +20 -0
- package/dist/src/targets/node/native/fixtures/text-plain.js +23 -0
- package/dist/src/targets/node/request/client.js +116 -0
- package/dist/src/targets/node/request/fixtures/application-form-encoded.js +13 -0
- package/dist/src/targets/node/request/fixtures/application-json.js +21 -0
- package/dist/src/targets/node/request/fixtures/cookies.js +11 -0
- package/dist/src/targets/node/request/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/request/fixtures/full.js +20 -0
- package/dist/src/targets/node/request/fixtures/headers.js +12 -0
- package/dist/src/targets/node/request/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/node/request/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/request/fixtures/multipart-file.js +19 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data-no-params.js +12 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data.js +13 -0
- package/dist/src/targets/node/request/fixtures/nested.js +11 -0
- package/dist/src/targets/node/request/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/node/request/fixtures/query.js +11 -0
- package/dist/src/targets/node/request/fixtures/short.js +8 -0
- package/dist/src/targets/node/request/fixtures/text-plain.js +13 -0
- package/dist/src/targets/node/target.js +24 -0
- package/dist/src/targets/node/unirest/client.js +119 -0
- package/dist/src/targets/node/unirest/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/application-json.js +32 -0
- package/dist/src/targets/node/unirest/fixtures/cookies.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/full.js +27 -0
- package/dist/src/targets/node/unirest/fixtures/headers.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-file.js +18 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/nested.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/query-encoded.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/query.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/short.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/text-plain.js +12 -0
- package/dist/src/targets/objc/helpers.js +59 -0
- package/dist/src/targets/objc/nsurlsession/client.js +151 -0
- package/dist/src/targets/objc/target.js +15 -0
- package/dist/src/targets/ocaml/cohttp/client.js +72 -0
- package/dist/src/targets/ocaml/target.js +15 -0
- package/dist/src/targets/php/curl/client.js +135 -0
- package/dist/src/targets/php/guzzle/client.js +126 -0
- package/dist/src/targets/php/helpers.js +63 -0
- package/dist/src/targets/php/http1/client.js +90 -0
- package/dist/src/targets/php/http2/client.js +128 -0
- package/dist/src/targets/php/target.js +22 -0
- package/dist/src/targets/powershell/common.js +49 -0
- package/dist/src/targets/powershell/restmethod/client.js +13 -0
- package/dist/src/targets/powershell/target.js +17 -0
- package/dist/src/targets/powershell/webrequest/client.js +13 -0
- package/dist/src/targets/python/helpers.js +70 -0
- package/dist/src/targets/python/requests/client.js +161 -0
- package/dist/src/targets/python/target.js +16 -0
- package/dist/src/targets/r/httr/client.js +125 -0
- package/dist/src/targets/r/target.js +15 -0
- package/dist/src/targets/ruby/native/client.js +69 -0
- package/dist/src/targets/ruby/target.js +15 -0
- package/dist/src/targets/shell/curl/client.js +171 -0
- package/dist/src/targets/shell/httpie/client.js +111 -0
- package/dist/src/targets/shell/target.js +20 -0
- package/dist/src/targets/shell/wget/client.js +55 -0
- package/dist/src/targets/swift/helpers.js +80 -0
- package/dist/src/targets/swift/nsurlsession/client.js +156 -0
- package/dist/src/targets/swift/target.js +15 -0
- package/dist/src/targets/targets.js +130 -0
- package/package.json +26 -21
- package/src/helpers/code-builder.js +0 -108
- package/src/helpers/form-data.js +0 -107
- package/src/helpers/headers.js +0 -48
- package/src/helpers/reducer.js +0 -20
- package/src/index.js +0 -361
- package/src/targets/c/index.js +0 -10
- package/src/targets/c/libcurl.js +0 -45
- package/src/targets/clojure/clj_http.js +0 -176
- package/src/targets/clojure/index.js +0 -10
- package/src/targets/csharp/httpclient.js +0 -157
- package/src/targets/csharp/index.js +0 -11
- package/src/targets/csharp/restsharp.js +0 -49
- package/src/targets/go/index.js +0 -10
- package/src/targets/go/native.js +0 -130
- package/src/targets/http/http1.1.js +0 -89
- package/src/targets/http/index.js +0 -10
- package/src/targets/index.js +0 -20
- package/src/targets/java/asynchttp.js +0 -54
- package/src/targets/java/index.js +0 -13
- package/src/targets/java/nethttp.js +0 -59
- package/src/targets/java/okhttp.js +0 -78
- package/src/targets/java/unirest.js +0 -57
- package/src/targets/javascript/axios.js +0 -101
- package/src/targets/javascript/fetch.js +0 -129
- package/src/targets/javascript/index.js +0 -13
- package/src/targets/javascript/jquery.js +0 -89
- package/src/targets/javascript/xhr.js +0 -86
- package/src/targets/kotlin/index.js +0 -10
- package/src/targets/kotlin/okhttp.js +0 -78
- package/src/targets/node/axios.js +0 -76
- package/src/targets/node/fetch.js +0 -145
- package/src/targets/node/index.js +0 -15
- package/src/targets/node/native.js +0 -92
- package/src/targets/node/request.js +0 -126
- package/src/targets/node/unirest.js +0 -120
- package/src/targets/objc/helpers.js +0 -80
- package/src/targets/objc/index.js +0 -10
- package/src/targets/objc/nsurlsession.js +0 -164
- package/src/targets/ocaml/cohttp.js +0 -73
- package/src/targets/ocaml/index.js +0 -10
- package/src/targets/php/curl.js +0 -142
- package/src/targets/php/guzzle.js +0 -135
- package/src/targets/php/helpers.js +0 -87
- package/src/targets/php/http1.js +0 -85
- package/src/targets/php/http2.js +0 -131
- package/src/targets/php/index.js +0 -14
- package/src/targets/powershell/common.js +0 -60
- package/src/targets/powershell/index.js +0 -11
- package/src/targets/powershell/restmethod.js +0 -8
- package/src/targets/powershell/webrequest.js +0 -8
- package/src/targets/python/helpers.js +0 -85
- package/src/targets/python/index.js +0 -11
- package/src/targets/python/requests.js +0 -163
- package/src/targets/r/httr.js +0 -134
- package/src/targets/r/index.js +0 -10
- package/src/targets/ruby/index.js +0 -10
- package/src/targets/ruby/native.js +0 -71
- package/src/targets/shell/curl.js +0 -157
- package/src/targets/shell/helpers.js +0 -23
- package/src/targets/shell/httpie.js +0 -129
- package/src/targets/shell/index.js +0 -13
- package/src/targets/shell/wget.js +0 -52
- package/src/targets/swift/helpers.js +0 -93
- package/src/targets/swift/index.js +0 -10
- package/src/targets/swift/nsurlsession.js +0 -152
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* HTTP code snippet generator for PHP using curl-ext.
|
|
5
|
+
*
|
|
6
|
+
* @author
|
|
7
|
+
* @AhmadNassri
|
|
8
|
+
*
|
|
9
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
10
|
+
*/
|
|
11
|
+
var __assign = (this && this.__assign) || function () {
|
|
12
|
+
__assign = Object.assign || function(t) {
|
|
13
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
14
|
+
s = arguments[i];
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
};
|
|
20
|
+
return __assign.apply(this, arguments);
|
|
21
|
+
};
|
|
22
|
+
exports.__esModule = true;
|
|
23
|
+
exports.http2 = void 0;
|
|
24
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
25
|
+
var headers_1 = require("../../../helpers/headers");
|
|
26
|
+
var helpers_1 = require("../helpers");
|
|
27
|
+
exports.http2 = {
|
|
28
|
+
info: {
|
|
29
|
+
key: 'http2',
|
|
30
|
+
title: 'HTTP v2',
|
|
31
|
+
link: 'http://devel-m6w6.rhcloud.com/mdref/http',
|
|
32
|
+
description: 'PHP with pecl/http v2'
|
|
33
|
+
},
|
|
34
|
+
convert: function (_a, options) {
|
|
35
|
+
var postData = _a.postData, headersObj = _a.headersObj, method = _a.method, queryObj = _a.queryObj, cookiesObj = _a.cookiesObj, url = _a.url;
|
|
36
|
+
var opts = __assign({ closingTag: false, indent: ' ', noTags: false, shortTags: false }, options);
|
|
37
|
+
var _b = new code_builder_1.CodeBuilder({ indent: opts.indent }), push = _b.push, blank = _b.blank, join = _b.join;
|
|
38
|
+
var hasBody = false;
|
|
39
|
+
if (!opts.noTags) {
|
|
40
|
+
push(opts.shortTags ? '<?' : '<?php');
|
|
41
|
+
blank();
|
|
42
|
+
}
|
|
43
|
+
push('$client = new http\\Client;');
|
|
44
|
+
push('$request = new http\\Client\\Request;');
|
|
45
|
+
blank();
|
|
46
|
+
switch (postData.mimeType) {
|
|
47
|
+
case 'application/x-www-form-urlencoded':
|
|
48
|
+
push('$body = new http\\Message\\Body;');
|
|
49
|
+
push("$body->append(new http\\QueryString(".concat((0, helpers_1.convertType)(postData.paramsObj, opts.indent), "));"));
|
|
50
|
+
blank();
|
|
51
|
+
hasBody = true;
|
|
52
|
+
break;
|
|
53
|
+
case 'multipart/form-data': {
|
|
54
|
+
if (!postData.params) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
var files_1 = [];
|
|
58
|
+
var fields_1 = {};
|
|
59
|
+
postData.params.forEach(function (_a) {
|
|
60
|
+
var name = _a.name, fileName = _a.fileName, value = _a.value, contentType = _a.contentType;
|
|
61
|
+
if (fileName) {
|
|
62
|
+
files_1.push({
|
|
63
|
+
name: name,
|
|
64
|
+
type: contentType,
|
|
65
|
+
file: fileName,
|
|
66
|
+
data: value
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (value) {
|
|
71
|
+
fields_1[name] = value;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
var field = Object.keys(fields_1).length ? (0, helpers_1.convertType)(fields_1, opts.indent) : 'null';
|
|
75
|
+
var formValue = files_1.length ? (0, helpers_1.convertType)(files_1, opts.indent) : 'null';
|
|
76
|
+
push('$body = new http\\Message\\Body;');
|
|
77
|
+
push("$body->addForm(".concat(field, ", ").concat(formValue, ");"));
|
|
78
|
+
// remove the contentType header
|
|
79
|
+
if ((0, headers_1.hasHeader)(headersObj, 'content-type')) {
|
|
80
|
+
if (String((0, headers_1.getHeader)(headersObj, 'content-type')).indexOf('boundary')) {
|
|
81
|
+
var headerName = (0, headers_1.getHeaderName)(headersObj, 'content-type');
|
|
82
|
+
if (headerName) {
|
|
83
|
+
delete headersObj[headerName];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
blank();
|
|
88
|
+
hasBody = true;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
if (postData.text) {
|
|
93
|
+
push('$body = new http\\Message\\Body;');
|
|
94
|
+
push("$body->append(".concat((0, helpers_1.convertType)(postData.text), ");"));
|
|
95
|
+
blank();
|
|
96
|
+
hasBody = true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
push("$request->setRequestUrl(".concat((0, helpers_1.convertType)(url), ");"));
|
|
100
|
+
push("$request->setRequestMethod(".concat((0, helpers_1.convertType)(method), ");"));
|
|
101
|
+
if (hasBody) {
|
|
102
|
+
push('$request->setBody($body);');
|
|
103
|
+
blank();
|
|
104
|
+
}
|
|
105
|
+
if (Object.keys(queryObj).length) {
|
|
106
|
+
push("$request->setQuery(new http\\QueryString(".concat((0, helpers_1.convertType)(queryObj, opts.indent), "));"));
|
|
107
|
+
blank();
|
|
108
|
+
}
|
|
109
|
+
if (Object.keys(headersObj).length) {
|
|
110
|
+
push("$request->setHeaders(".concat((0, helpers_1.convertType)(headersObj, opts.indent), ");"));
|
|
111
|
+
blank();
|
|
112
|
+
}
|
|
113
|
+
if (Object.keys(cookiesObj).length) {
|
|
114
|
+
blank();
|
|
115
|
+
push("$client->setCookies(".concat((0, helpers_1.convertType)(cookiesObj, opts.indent), ");"));
|
|
116
|
+
blank();
|
|
117
|
+
}
|
|
118
|
+
push('$client->enqueue($request)->send();');
|
|
119
|
+
push('$response = $client->getResponse();');
|
|
120
|
+
blank();
|
|
121
|
+
push('echo $response->getBody();');
|
|
122
|
+
if (!opts.noTags && opts.closingTag) {
|
|
123
|
+
blank();
|
|
124
|
+
push('?>');
|
|
125
|
+
}
|
|
126
|
+
return join();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.php = void 0;
|
|
4
|
+
var client_1 = require("./curl/client");
|
|
5
|
+
var client_2 = require("./guzzle/client");
|
|
6
|
+
var client_3 = require("./http1/client");
|
|
7
|
+
var client_4 = require("./http2/client");
|
|
8
|
+
exports.php = {
|
|
9
|
+
info: {
|
|
10
|
+
key: 'php',
|
|
11
|
+
title: 'PHP',
|
|
12
|
+
extname: '.php',
|
|
13
|
+
"default": 'curl',
|
|
14
|
+
cli: 'php %s'
|
|
15
|
+
},
|
|
16
|
+
clientsById: {
|
|
17
|
+
curl: client_1.curl,
|
|
18
|
+
guzzle: client_2.guzzle,
|
|
19
|
+
http1: client_3.http1,
|
|
20
|
+
http2: client_4.http2
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.generatePowershellConvert = void 0;
|
|
4
|
+
var code_builder_1 = require("../../helpers/code-builder");
|
|
5
|
+
var headers_1 = require("../../helpers/headers");
|
|
6
|
+
var generatePowershellConvert = function (command) {
|
|
7
|
+
var convert = function (_a) {
|
|
8
|
+
var method = _a.method, headersObj = _a.headersObj, cookies = _a.cookies, uriObj = _a.uriObj, fullUrl = _a.fullUrl, postData = _a.postData, allHeaders = _a.allHeaders;
|
|
9
|
+
var _b = new code_builder_1.CodeBuilder(), push = _b.push, join = _b.join;
|
|
10
|
+
var methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
|
11
|
+
if (!methods.includes(method.toUpperCase())) {
|
|
12
|
+
return 'Method not supported';
|
|
13
|
+
}
|
|
14
|
+
var commandOptions = [];
|
|
15
|
+
// Add headers, including the cookies
|
|
16
|
+
var headers = Object.keys(headersObj);
|
|
17
|
+
// construct headers
|
|
18
|
+
if (headers.length) {
|
|
19
|
+
push('$headers=@{}');
|
|
20
|
+
headers.forEach(function (key) {
|
|
21
|
+
if (key !== 'connection') {
|
|
22
|
+
// Not allowed
|
|
23
|
+
push("$headers.Add(\"".concat(key, "\", \"").concat(headersObj[key], "\")"));
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
commandOptions.push('-Headers $headers');
|
|
27
|
+
}
|
|
28
|
+
// construct cookies
|
|
29
|
+
if (cookies.length) {
|
|
30
|
+
push('$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession');
|
|
31
|
+
cookies.forEach(function (cookie) {
|
|
32
|
+
push('$cookie = New-Object System.Net.Cookie');
|
|
33
|
+
push("$cookie.Name = '".concat(cookie.name, "'"));
|
|
34
|
+
push("$cookie.Value = '".concat(cookie.value, "'"));
|
|
35
|
+
push("$cookie.Domain = '".concat(uriObj.host, "'"));
|
|
36
|
+
push('$session.Cookies.Add($cookie)');
|
|
37
|
+
});
|
|
38
|
+
commandOptions.push('-WebSession $session');
|
|
39
|
+
}
|
|
40
|
+
if (postData.text) {
|
|
41
|
+
commandOptions.push("-ContentType '".concat((0, headers_1.getHeader)(allHeaders, 'content-type'), "'"));
|
|
42
|
+
commandOptions.push("-Body '".concat(postData.text, "'"));
|
|
43
|
+
}
|
|
44
|
+
push("$response = ".concat(command, " -Uri '").concat(fullUrl, "' -Method ").concat(method, " ").concat(commandOptions.join(' ')).trim());
|
|
45
|
+
return join();
|
|
46
|
+
};
|
|
47
|
+
return convert;
|
|
48
|
+
};
|
|
49
|
+
exports.generatePowershellConvert = generatePowershellConvert;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.restmethod = void 0;
|
|
4
|
+
var common_1 = require("../common");
|
|
5
|
+
exports.restmethod = {
|
|
6
|
+
info: {
|
|
7
|
+
key: 'restmethod',
|
|
8
|
+
title: 'Invoke-RestMethod',
|
|
9
|
+
link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod',
|
|
10
|
+
description: 'Powershell Invoke-RestMethod client'
|
|
11
|
+
},
|
|
12
|
+
convert: (0, common_1.generatePowershellConvert)('Invoke-RestMethod')
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.powershell = void 0;
|
|
4
|
+
var client_1 = require("./restmethod/client");
|
|
5
|
+
var client_2 = require("./webrequest/client");
|
|
6
|
+
exports.powershell = {
|
|
7
|
+
info: {
|
|
8
|
+
key: 'powershell',
|
|
9
|
+
title: 'Powershell',
|
|
10
|
+
extname: '.ps1',
|
|
11
|
+
"default": 'webrequest'
|
|
12
|
+
},
|
|
13
|
+
clientsById: {
|
|
14
|
+
webrequest: client_2.webrequest,
|
|
15
|
+
restmethod: client_1.restmethod
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.webrequest = void 0;
|
|
4
|
+
var common_1 = require("../common");
|
|
5
|
+
exports.webrequest = {
|
|
6
|
+
info: {
|
|
7
|
+
key: 'webrequest',
|
|
8
|
+
title: 'Invoke-WebRequest',
|
|
9
|
+
link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-WebRequest',
|
|
10
|
+
description: 'Powershell Invoke-WebRequest client'
|
|
11
|
+
},
|
|
12
|
+
convert: (0, common_1.generatePowershellConvert)('Invoke-WebRequest')
|
|
13
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.literalRepresentation = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Create an string of given length filled with blank spaces
|
|
6
|
+
*
|
|
7
|
+
* @param length Length of the array to return
|
|
8
|
+
* @param str String to pad out with
|
|
9
|
+
*/
|
|
10
|
+
function buildString(length, str) {
|
|
11
|
+
return str.repeat(length);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a string corresponding to a Dictionary or Array literal representation with pretty option
|
|
15
|
+
* and indentation.
|
|
16
|
+
*/
|
|
17
|
+
function concatValues(concatType, values, pretty, indentation, indentLevel) {
|
|
18
|
+
var currentIndent = buildString(indentLevel, indentation);
|
|
19
|
+
var closingBraceIndent = buildString(indentLevel - 1, indentation);
|
|
20
|
+
var join = pretty ? ",\n".concat(currentIndent) : ', ';
|
|
21
|
+
var openingBrace = concatType === 'object' ? '{' : '[';
|
|
22
|
+
var closingBrace = concatType === 'object' ? '}' : ']';
|
|
23
|
+
if (pretty) {
|
|
24
|
+
return "".concat(openingBrace, "\n").concat(currentIndent).concat(values.join(join), "\n").concat(closingBraceIndent).concat(closingBrace);
|
|
25
|
+
}
|
|
26
|
+
return openingBrace + values.join(join) + closingBrace;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a valid Python string of a literal value according to its type.
|
|
30
|
+
*
|
|
31
|
+
* @param {*} value Any JavaScript literal
|
|
32
|
+
* @param {Object} opts Target options
|
|
33
|
+
* @return {string}
|
|
34
|
+
*/
|
|
35
|
+
var literalRepresentation = function (value, opts, indentLevel) {
|
|
36
|
+
indentLevel = indentLevel === undefined ? 1 : indentLevel + 1;
|
|
37
|
+
switch (Object.prototype.toString.call(value)) {
|
|
38
|
+
case '[object Number]':
|
|
39
|
+
return value;
|
|
40
|
+
case '[object Array]': {
|
|
41
|
+
var pretty_1 = false;
|
|
42
|
+
var valuesRepresentation = value.map(function (v) {
|
|
43
|
+
// Switch to prettify if the value is a dictionary with multiple keys
|
|
44
|
+
if (Object.prototype.toString.call(v) === '[object Object]') {
|
|
45
|
+
pretty_1 = Object.keys(v).length > 1;
|
|
46
|
+
}
|
|
47
|
+
return (0, exports.literalRepresentation)(v, opts, indentLevel);
|
|
48
|
+
});
|
|
49
|
+
return concatValues('array', valuesRepresentation, pretty_1, opts.indent, indentLevel);
|
|
50
|
+
}
|
|
51
|
+
case '[object Object]': {
|
|
52
|
+
var keyValuePairs = [];
|
|
53
|
+
// eslint-disable-next-line guard-for-in, no-restricted-syntax
|
|
54
|
+
for (var key in value) {
|
|
55
|
+
keyValuePairs.push("\"".concat(key, "\": ").concat((0, exports.literalRepresentation)(value[key], opts, indentLevel)));
|
|
56
|
+
}
|
|
57
|
+
return concatValues('object', keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel);
|
|
58
|
+
}
|
|
59
|
+
case '[object Null]':
|
|
60
|
+
return 'None';
|
|
61
|
+
case '[object Boolean]':
|
|
62
|
+
return value ? 'True' : 'False';
|
|
63
|
+
default:
|
|
64
|
+
if (value === null || value === undefined) {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
return "\"".concat(value.toString().replace(/"/g, '\\"'), "\"");
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.literalRepresentation = literalRepresentation;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* HTTP code snippet generator for Python using Requests
|
|
5
|
+
*
|
|
6
|
+
* @author
|
|
7
|
+
* @montanaflynn
|
|
8
|
+
*
|
|
9
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
10
|
+
*/
|
|
11
|
+
var __assign = (this && this.__assign) || function () {
|
|
12
|
+
__assign = Object.assign || function(t) {
|
|
13
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
14
|
+
s = arguments[i];
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
};
|
|
20
|
+
return __assign.apply(this, arguments);
|
|
21
|
+
};
|
|
22
|
+
exports.__esModule = true;
|
|
23
|
+
exports.requests = void 0;
|
|
24
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
25
|
+
var headers_1 = require("../../../helpers/headers");
|
|
26
|
+
var helpers_1 = require("../helpers");
|
|
27
|
+
exports.requests = {
|
|
28
|
+
info: {
|
|
29
|
+
key: 'requests',
|
|
30
|
+
title: 'Requests',
|
|
31
|
+
link: 'http://docs.python-requests.org/en/latest/api/#requests.request',
|
|
32
|
+
description: 'Requests HTTP library'
|
|
33
|
+
},
|
|
34
|
+
convert: function (_a, options) {
|
|
35
|
+
var fullUrl = _a.fullUrl, postData = _a.postData, allHeaders = _a.allHeaders, method = _a.method;
|
|
36
|
+
var opts = __assign({ indent: ' ', pretty: true }, options);
|
|
37
|
+
// Start snippet
|
|
38
|
+
var _b = new code_builder_1.CodeBuilder({ indent: opts.indent }), push = _b.push, blank = _b.blank, join = _b.join, addPostProcessor = _b.addPostProcessor;
|
|
39
|
+
// Import requests
|
|
40
|
+
push('import requests');
|
|
41
|
+
blank();
|
|
42
|
+
// Set URL
|
|
43
|
+
push("url = \"".concat(fullUrl, "\""));
|
|
44
|
+
blank();
|
|
45
|
+
var headers = allHeaders;
|
|
46
|
+
// Construct payload
|
|
47
|
+
var payload = {};
|
|
48
|
+
var files = {};
|
|
49
|
+
var hasFiles = false;
|
|
50
|
+
var hasPayload = false;
|
|
51
|
+
var jsonPayload = false;
|
|
52
|
+
switch (postData.mimeType) {
|
|
53
|
+
case 'application/json':
|
|
54
|
+
if (postData.jsonObj) {
|
|
55
|
+
push("payload = ".concat((0, helpers_1.literalRepresentation)(postData.jsonObj, opts)));
|
|
56
|
+
jsonPayload = true;
|
|
57
|
+
hasPayload = true;
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
case 'multipart/form-data':
|
|
61
|
+
if (!postData.params) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
payload = {};
|
|
65
|
+
postData.params.forEach(function (p) {
|
|
66
|
+
if (p.fileName) {
|
|
67
|
+
files[p.name] = "open('".concat(p.fileName, "', 'rb')");
|
|
68
|
+
hasFiles = true;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
payload[p.name] = p.value;
|
|
72
|
+
hasPayload = true;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (hasFiles) {
|
|
76
|
+
push("files = ".concat((0, helpers_1.literalRepresentation)(files, opts)));
|
|
77
|
+
if (hasPayload) {
|
|
78
|
+
push("payload = ".concat((0, helpers_1.literalRepresentation)(payload, opts)));
|
|
79
|
+
}
|
|
80
|
+
// The requests library will only automatically add a `multipart/form-data` header if there are files being sent. If we're **only** sending form data we still need to send the boundary ourselves.
|
|
81
|
+
var headerName = (0, headers_1.getHeaderName)(headers, 'content-type');
|
|
82
|
+
if (headerName) {
|
|
83
|
+
delete headers[headerName];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
var nonFilePayload = JSON.stringify(postData.text);
|
|
88
|
+
if (nonFilePayload) {
|
|
89
|
+
push("payload = ".concat(nonFilePayload));
|
|
90
|
+
hasPayload = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// The `open()` call must be a literal in the code snippet.
|
|
94
|
+
addPostProcessor(function (code) { return code.replace(/"open\('(.+)', 'rb'\)"/g, 'open("$1", "rb")'); });
|
|
95
|
+
break;
|
|
96
|
+
default: {
|
|
97
|
+
var stringPayload = JSON.stringify(postData.text);
|
|
98
|
+
if (stringPayload) {
|
|
99
|
+
push("payload = ".concat(stringPayload));
|
|
100
|
+
hasPayload = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Construct headers
|
|
105
|
+
var headerCount = Object.keys(headers).length;
|
|
106
|
+
if (headerCount === 0 && (hasPayload || hasFiles)) {
|
|
107
|
+
// If we don't have any heads but we do have a payload we should put a blank line here between that payload consturction and our execution of the requests library.
|
|
108
|
+
blank();
|
|
109
|
+
}
|
|
110
|
+
else if (headerCount === 1) {
|
|
111
|
+
Object.keys(headers).forEach(function (header) {
|
|
112
|
+
push("headers = {\"".concat(header, "\": \"").concat(headers[header], "\"}"));
|
|
113
|
+
blank();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
else if (headerCount > 1) {
|
|
117
|
+
var count_1 = 1;
|
|
118
|
+
push('headers = {');
|
|
119
|
+
Object.keys(headers).forEach(function (header) {
|
|
120
|
+
if (count_1 !== headerCount) {
|
|
121
|
+
push("\"".concat(header, "\": \"").concat(headers[header], "\","), 1);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
push("\"".concat(header, "\": \"").concat(headers[header], "\""), 1);
|
|
125
|
+
}
|
|
126
|
+
count_1 += 1;
|
|
127
|
+
});
|
|
128
|
+
push('}');
|
|
129
|
+
blank();
|
|
130
|
+
}
|
|
131
|
+
// Construct request
|
|
132
|
+
var request;
|
|
133
|
+
// Method list pulled from their api reference https://docs.python-requests.org/en/latest/api/#requests.head
|
|
134
|
+
if (['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) {
|
|
135
|
+
request = "response = requests.".concat(method.toLowerCase(), "(url");
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
request = "response = requests.request(\"".concat(method, "\", url");
|
|
139
|
+
}
|
|
140
|
+
if (hasPayload) {
|
|
141
|
+
if (jsonPayload) {
|
|
142
|
+
request += ', json=payload';
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
request += ', data=payload';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (hasFiles) {
|
|
149
|
+
request += ', files=files';
|
|
150
|
+
}
|
|
151
|
+
if (headerCount > 0) {
|
|
152
|
+
request += ', headers=headers';
|
|
153
|
+
}
|
|
154
|
+
request += ')';
|
|
155
|
+
push(request);
|
|
156
|
+
blank();
|
|
157
|
+
// Print response
|
|
158
|
+
push('print(response.text)');
|
|
159
|
+
return join();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.python = void 0;
|
|
4
|
+
var client_1 = require("./requests/client");
|
|
5
|
+
exports.python = {
|
|
6
|
+
info: {
|
|
7
|
+
key: 'python',
|
|
8
|
+
title: 'Python',
|
|
9
|
+
extname: '.py',
|
|
10
|
+
"default": 'requests',
|
|
11
|
+
cli: 'python3 %s'
|
|
12
|
+
},
|
|
13
|
+
clientsById: {
|
|
14
|
+
requests: client_1.requests
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* HTTP code snippet generator for R using httr
|
|
5
|
+
*
|
|
6
|
+
* @author
|
|
7
|
+
* @gabrielakoreeda
|
|
8
|
+
*
|
|
9
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
10
|
+
*/
|
|
11
|
+
exports.__esModule = true;
|
|
12
|
+
exports.httr = void 0;
|
|
13
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
14
|
+
exports.httr = {
|
|
15
|
+
info: {
|
|
16
|
+
key: 'httr',
|
|
17
|
+
title: 'httr',
|
|
18
|
+
link: 'https://cran.r-project.org/web/packages/httr/vignettes/quickstart.html',
|
|
19
|
+
description: 'httr: Tools for Working with URLs and HTTP'
|
|
20
|
+
},
|
|
21
|
+
convert: function (_a) {
|
|
22
|
+
var url = _a.url, queryObj = _a.queryObj, queryString = _a.queryString, postData = _a.postData, allHeaders = _a.allHeaders, method = _a.method;
|
|
23
|
+
// Start snippet
|
|
24
|
+
var _b = new code_builder_1.CodeBuilder(), push = _b.push, blank = _b.blank, join = _b.join;
|
|
25
|
+
// Import httr
|
|
26
|
+
push('library(httr)');
|
|
27
|
+
blank();
|
|
28
|
+
// Set URL
|
|
29
|
+
push("url <- \"".concat(url, "\""));
|
|
30
|
+
blank();
|
|
31
|
+
// Construct query string
|
|
32
|
+
var qs = queryObj;
|
|
33
|
+
delete queryObj.key;
|
|
34
|
+
var queryCount = Object.keys(qs).length;
|
|
35
|
+
if (queryString.length === 1) {
|
|
36
|
+
push("queryString <- list(".concat(Object.keys(qs), " = \"").concat(Object.values(qs).toString(), "\")"));
|
|
37
|
+
blank();
|
|
38
|
+
}
|
|
39
|
+
else if (queryString.length > 1) {
|
|
40
|
+
push('queryString <- list(');
|
|
41
|
+
Object.keys(qs).forEach(function (query, i) {
|
|
42
|
+
if (i !== queryCount - 1) {
|
|
43
|
+
push(" ".concat(query, " = \"").concat(qs[query].toString(), "\","));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
push(" ".concat(query, " = \"").concat(qs[query].toString(), "\""));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
push(')');
|
|
50
|
+
blank();
|
|
51
|
+
}
|
|
52
|
+
// Construct payload
|
|
53
|
+
var payload = JSON.stringify(postData.text);
|
|
54
|
+
if (payload) {
|
|
55
|
+
push("payload <- ".concat(payload));
|
|
56
|
+
blank();
|
|
57
|
+
}
|
|
58
|
+
// Define encode
|
|
59
|
+
if (postData.text || postData.jsonObj || postData.params) {
|
|
60
|
+
switch (postData.mimeType) {
|
|
61
|
+
case 'application/x-www-form-urlencoded':
|
|
62
|
+
push('encode <- "form"');
|
|
63
|
+
blank();
|
|
64
|
+
break;
|
|
65
|
+
case 'application/json':
|
|
66
|
+
push('encode <- "json"');
|
|
67
|
+
blank();
|
|
68
|
+
break;
|
|
69
|
+
case 'multipart/form-data':
|
|
70
|
+
push('encode <- "multipart"');
|
|
71
|
+
blank();
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
push('encode <- "raw"');
|
|
75
|
+
blank();
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Construct headers
|
|
80
|
+
var headers = [];
|
|
81
|
+
var cookies;
|
|
82
|
+
var accept;
|
|
83
|
+
Object.keys(allHeaders).forEach(function (header) {
|
|
84
|
+
if (header.toLowerCase() === 'accept') {
|
|
85
|
+
accept = ", accept(\"".concat(allHeaders[header], "\")");
|
|
86
|
+
}
|
|
87
|
+
else if (header.toLowerCase() === 'cookie') {
|
|
88
|
+
cookies = ", set_cookies(`".concat(String(allHeaders[header])
|
|
89
|
+
.replace(/;/g, '", `')
|
|
90
|
+
.replace(/` /g, '`')
|
|
91
|
+
.replace(/[=]/g, '` = "'), "\")");
|
|
92
|
+
}
|
|
93
|
+
else if (header.toLowerCase() !== 'content-type') {
|
|
94
|
+
headers.push("'".concat(header, "' = '").concat(allHeaders[header], "'"));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
// Construct request
|
|
98
|
+
var request = "response <- VERB(\"".concat(method, "\", url");
|
|
99
|
+
if (payload) {
|
|
100
|
+
request += ', body = payload';
|
|
101
|
+
}
|
|
102
|
+
if (headers.length) {
|
|
103
|
+
request += ", add_headers(".concat(headers.join(', '), ")");
|
|
104
|
+
}
|
|
105
|
+
if (queryString.length) {
|
|
106
|
+
request += ', query = queryString';
|
|
107
|
+
}
|
|
108
|
+
request += ", content_type(\"".concat(postData.mimeType, "\")");
|
|
109
|
+
if (typeof accept !== 'undefined') {
|
|
110
|
+
request += accept;
|
|
111
|
+
}
|
|
112
|
+
if (typeof cookies !== 'undefined') {
|
|
113
|
+
request += cookies;
|
|
114
|
+
}
|
|
115
|
+
if (postData.text || postData.jsonObj || postData.params) {
|
|
116
|
+
request += ', encode = encode';
|
|
117
|
+
}
|
|
118
|
+
request += ')';
|
|
119
|
+
push(request);
|
|
120
|
+
blank();
|
|
121
|
+
// Print response
|
|
122
|
+
push('content(response, "text")');
|
|
123
|
+
return join();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.r = void 0;
|
|
4
|
+
var client_1 = require("./httr/client");
|
|
5
|
+
exports.r = {
|
|
6
|
+
info: {
|
|
7
|
+
key: 'r',
|
|
8
|
+
title: 'R',
|
|
9
|
+
extname: '.r',
|
|
10
|
+
"default": 'httr'
|
|
11
|
+
},
|
|
12
|
+
clientsById: {
|
|
13
|
+
httr: client_1.httr
|
|
14
|
+
}
|
|
15
|
+
};
|