@scalar/snippetz 0.7.3 → 0.7.5
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/dist/clients/index.js +168 -169
- package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
- package/dist/httpsnippet-lite/helpers/escape.js +69 -44
- package/dist/httpsnippet-lite/helpers/headers.js +17 -14
- package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
- package/dist/httpsnippet-lite/helpers/shell.js +13 -13
- package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
- package/dist/httpsnippet-lite/helpers/url.js +4 -8
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
- package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
- package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
- package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
- package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
- package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
- package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
- package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
- package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
- package/dist/httpsnippet-lite/targets/target.js +1 -1
- package/dist/index.js +2 -9
- package/dist/libs/http.js +68 -56
- package/dist/libs/javascript.js +77 -60
- package/dist/libs/php.js +59 -49
- package/dist/libs/rust.js +60 -33
- package/dist/libs/shell.js +14 -5
- package/dist/plugins/c/libcurl/index.js +1 -5
- package/dist/plugins/c/libcurl/libcurl.js +13 -13
- package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
- package/dist/plugins/clojure/clj_http/index.js +1 -5
- package/dist/plugins/csharp/httpclient/httpclient.js +186 -150
- package/dist/plugins/csharp/httpclient/index.js +1 -5
- package/dist/plugins/csharp/restsharp/index.js +1 -5
- package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
- package/dist/plugins/dart/http/http.js +95 -93
- package/dist/plugins/dart/http/index.js +1 -5
- package/dist/plugins/fsharp/httpclient/httpclient.js +156 -122
- package/dist/plugins/fsharp/httpclient/index.js +1 -5
- package/dist/plugins/go/native/index.js +1 -5
- package/dist/plugins/go/native/native.js +13 -13
- package/dist/plugins/http/http11/http11.js +103 -85
- package/dist/plugins/http/http11/index.js +1 -5
- package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
- package/dist/plugins/java/asynchttp/index.js +1 -5
- package/dist/plugins/java/nethttp/index.js +1 -5
- package/dist/plugins/java/nethttp/nethttp.js +13 -13
- package/dist/plugins/java/okhttp/index.js +1 -5
- package/dist/plugins/java/okhttp/okhttp.js +13 -13
- package/dist/plugins/java/unirest/index.js +1 -5
- package/dist/plugins/java/unirest/unirest.js +13 -13
- package/dist/plugins/js/axios/axios.js +13 -13
- package/dist/plugins/js/axios/index.js +1 -5
- package/dist/plugins/js/fetch/fetch.js +82 -68
- package/dist/plugins/js/fetch/index.js +1 -5
- package/dist/plugins/js/jquery/index.js +1 -5
- package/dist/plugins/js/jquery/jquery.js +13 -13
- package/dist/plugins/js/ofetch/index.js +1 -5
- package/dist/plugins/js/ofetch/ofetch.js +61 -48
- package/dist/plugins/js/xhr/index.js +1 -5
- package/dist/plugins/js/xhr/xhr.js +13 -13
- package/dist/plugins/kotlin/okhttp/index.js +1 -5
- package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
- package/dist/plugins/node/axios/axios.js +13 -13
- package/dist/plugins/node/axios/index.js +1 -5
- package/dist/plugins/node/fetch/fetch.js +86 -74
- package/dist/plugins/node/fetch/index.js +1 -5
- package/dist/plugins/node/ofetch/index.js +1 -5
- package/dist/plugins/node/ofetch/ofetch.js +61 -48
- package/dist/plugins/node/undici/index.js +1 -5
- package/dist/plugins/node/undici/undici.js +60 -47
- package/dist/plugins/objc/nsurlsession/index.js +1 -5
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
- package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
- package/dist/plugins/ocaml/cohttp/index.js +1 -5
- package/dist/plugins/php/curl/curl.js +143 -101
- package/dist/plugins/php/curl/index.js +1 -5
- package/dist/plugins/php/guzzle/guzzle.js +103 -83
- package/dist/plugins/php/guzzle/index.js +1 -5
- package/dist/plugins/powershell/restmethod/index.js +1 -5
- package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
- package/dist/plugins/powershell/webrequest/index.js +1 -5
- package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
- package/dist/plugins/python/httpx/async.js +17 -15
- package/dist/plugins/python/httpx/index.js +2 -7
- package/dist/plugins/python/httpx/sync.js +11 -12
- package/dist/plugins/python/python3/index.js +1 -5
- package/dist/plugins/python/python3/python3.js +13 -13
- package/dist/plugins/python/requests/index.js +1 -5
- package/dist/plugins/python/requests/requests.js +11 -12
- package/dist/plugins/python/requestsLike.js +128 -112
- package/dist/plugins/r/httr/httr.js +13 -13
- package/dist/plugins/r/httr/index.js +1 -5
- package/dist/plugins/ruby/native/index.js +1 -5
- package/dist/plugins/ruby/native/native.js +13 -13
- package/dist/plugins/rust/reqwest/index.js +1 -5
- package/dist/plugins/rust/reqwest/reqwest.js +110 -83
- package/dist/plugins/shell/curl/curl.js +128 -97
- package/dist/plugins/shell/curl/index.js +1 -5
- package/dist/plugins/shell/httpie/httpie.js +13 -13
- package/dist/plugins/shell/httpie/index.js +1 -5
- package/dist/plugins/shell/wget/index.js +1 -5
- package/dist/plugins/shell/wget/wget.js +13 -13
- package/dist/plugins/swift/nsurlsession/index.js +1 -5
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
- package/dist/snippetz.js +25 -28
- package/dist/utils/convertWithHttpSnippetLite.js +100 -96
- package/dist/utils/index.js +1 -5
- package/package.json +8 -12
- package/dist/clients/index.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/target.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/libs/http.js.map +0 -7
- package/dist/libs/javascript.js.map +0 -7
- package/dist/libs/php.js.map +0 -7
- package/dist/libs/rust.js.map +0 -7
- package/dist/libs/shell.js.map +0 -7
- package/dist/plugins/c/libcurl/index.js.map +0 -7
- package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
- package/dist/plugins/clojure/clj_http/index.js.map +0 -7
- package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/csharp/httpclient/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
- package/dist/plugins/dart/http/http.js.map +0 -7
- package/dist/plugins/dart/http/index.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
- package/dist/plugins/go/native/index.js.map +0 -7
- package/dist/plugins/go/native/native.js.map +0 -7
- package/dist/plugins/http/http11/http11.js.map +0 -7
- package/dist/plugins/http/http11/index.js.map +0 -7
- package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
- package/dist/plugins/java/asynchttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
- package/dist/plugins/java/okhttp/index.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/java/unirest/index.js.map +0 -7
- package/dist/plugins/java/unirest/unirest.js.map +0 -7
- package/dist/plugins/js/axios/axios.js.map +0 -7
- package/dist/plugins/js/axios/index.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.js.map +0 -7
- package/dist/plugins/js/fetch/index.js.map +0 -7
- package/dist/plugins/js/jquery/index.js.map +0 -7
- package/dist/plugins/js/jquery/jquery.js.map +0 -7
- package/dist/plugins/js/ofetch/index.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/js/xhr/index.js.map +0 -7
- package/dist/plugins/js/xhr/xhr.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/node/axios/axios.js.map +0 -7
- package/dist/plugins/node/axios/index.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.js.map +0 -7
- package/dist/plugins/node/fetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/node/undici/index.js.map +0 -7
- package/dist/plugins/node/undici/undici.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
- package/dist/plugins/php/curl/curl.js.map +0 -7
- package/dist/plugins/php/curl/index.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
- package/dist/plugins/php/guzzle/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
- package/dist/plugins/powershell/webrequest/index.js.map +0 -7
- package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
- package/dist/plugins/python/httpx/async.js.map +0 -7
- package/dist/plugins/python/httpx/index.js.map +0 -7
- package/dist/plugins/python/httpx/sync.js.map +0 -7
- package/dist/plugins/python/python3/index.js.map +0 -7
- package/dist/plugins/python/python3/python3.js.map +0 -7
- package/dist/plugins/python/requests/index.js.map +0 -7
- package/dist/plugins/python/requests/requests.js.map +0 -7
- package/dist/plugins/python/requestsLike.js.map +0 -7
- package/dist/plugins/r/httr/httr.js.map +0 -7
- package/dist/plugins/r/httr/index.js.map +0 -7
- package/dist/plugins/ruby/native/index.js.map +0 -7
- package/dist/plugins/ruby/native/native.js.map +0 -7
- package/dist/plugins/rust/reqwest/index.js.map +0 -7
- package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
- package/dist/plugins/shell/curl/curl.js.map +0 -7
- package/dist/plugins/shell/curl/index.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.js.map +0 -7
- package/dist/plugins/shell/httpie/index.js.map +0 -7
- package/dist/plugins/shell/wget/index.js.map +0 -7
- package/dist/plugins/shell/wget/wget.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/snippetz.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
- package/dist/utils/index.js.map +0 -7
|
@@ -1,35 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for Java using Unirest.
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @shashiranjan84
|
|
7
|
+
*
|
|
8
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
+
*/
|
|
10
|
+
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
11
|
+
import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
|
|
12
|
+
export const unirest = {
|
|
13
|
+
info: {
|
|
14
|
+
key: 'unirest',
|
|
15
|
+
title: 'Unirest',
|
|
16
|
+
link: 'http://unirest.io/java.html',
|
|
17
|
+
description: 'Lightweight HTTP Request Client Library',
|
|
18
|
+
},
|
|
19
|
+
convert: ({ method, allHeaders, postData, fullUrl }, options) => {
|
|
20
|
+
const opts = {
|
|
21
|
+
indent: ' ',
|
|
22
|
+
...options,
|
|
23
|
+
};
|
|
24
|
+
const { join, push } = new CodeBuilder({ indent: opts.indent });
|
|
25
|
+
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
|
26
|
+
if (!methods.includes(method.toUpperCase())) {
|
|
27
|
+
push(`HttpResponse<String> response = Unirest.customMethod("${method.toUpperCase()}","${fullUrl}")`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
push(`HttpResponse<String> response = Unirest.${method.toLowerCase()}("${fullUrl}")`);
|
|
31
|
+
}
|
|
32
|
+
// Add headers, including the cookies
|
|
33
|
+
Object.keys(allHeaders).forEach((key) => {
|
|
34
|
+
push(`.header("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
|
|
35
|
+
});
|
|
36
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
37
|
+
push(`.body(${JSON.stringify(postData.text)})`, 1);
|
|
38
|
+
}
|
|
39
|
+
push('.asString();', 1);
|
|
40
|
+
return join();
|
|
41
|
+
},
|
|
31
42
|
};
|
|
32
|
-
export {
|
|
33
|
-
unirest
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,81 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
36
|
-
});
|
|
37
|
-
blank();
|
|
38
|
-
requestOptions.data = "encodedParams,";
|
|
39
|
-
addPostProcessor((code) => code.replace(/'encodedParams,'/, "encodedParams,"));
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for Javascript & Node.js using Axios.
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @rohit-gohri
|
|
7
|
+
*
|
|
8
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
+
*/
|
|
10
|
+
import stringifyObject from 'stringify-object';
|
|
11
|
+
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
12
|
+
export const axios = {
|
|
13
|
+
info: {
|
|
14
|
+
key: 'axios',
|
|
15
|
+
title: 'Axios',
|
|
16
|
+
link: 'https://github.com/axios/axios',
|
|
17
|
+
description: 'Promise based HTTP client for the browser and node.js',
|
|
18
|
+
},
|
|
19
|
+
convert: ({ allHeaders, method, url, queryObj, postData }, options) => {
|
|
20
|
+
const opts = {
|
|
21
|
+
indent: ' ',
|
|
22
|
+
...options,
|
|
23
|
+
};
|
|
24
|
+
const { blank, push, join, addPostProcessor } = new CodeBuilder({
|
|
25
|
+
indent: opts.indent,
|
|
26
|
+
});
|
|
27
|
+
push("import axios from 'axios';");
|
|
28
|
+
blank();
|
|
29
|
+
const requestOptions = {
|
|
30
|
+
method,
|
|
31
|
+
url,
|
|
32
|
+
};
|
|
33
|
+
if (Object.keys(queryObj).length) {
|
|
34
|
+
requestOptions.params = queryObj;
|
|
40
35
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (postData?.jsonObj) {
|
|
44
|
-
requestOptions.data = postData.jsonObj;
|
|
36
|
+
if (Object.keys(allHeaders).length) {
|
|
37
|
+
requestOptions.headers = allHeaders;
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
|
|
40
|
+
case 'application/x-www-form-urlencoded':
|
|
41
|
+
if (postData?.params) {
|
|
42
|
+
push('const encodedParams = new URLSearchParams();');
|
|
43
|
+
postData.params.forEach((param) => {
|
|
44
|
+
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
45
|
+
});
|
|
46
|
+
blank();
|
|
47
|
+
requestOptions.data = 'encodedParams,';
|
|
48
|
+
addPostProcessor((code) => code.replace(/'encodedParams,'/, 'encodedParams,'));
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case 'application/json':
|
|
52
|
+
if (postData?.jsonObj) {
|
|
53
|
+
requestOptions.data = postData.jsonObj;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'multipart/form-data':
|
|
57
|
+
if (!postData?.params) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
push('const form = new FormData();');
|
|
61
|
+
postData.params.forEach((param) => {
|
|
62
|
+
push(`form.append('${param.name}', '${param.value || param.fileName || ''}');`);
|
|
63
|
+
});
|
|
64
|
+
blank();
|
|
65
|
+
requestOptions.data = '[form]';
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
69
|
+
requestOptions.data = postData.text;
|
|
70
|
+
}
|
|
50
71
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
72
|
+
const optionString = stringifyObject(requestOptions, {
|
|
73
|
+
indent: ' ',
|
|
74
|
+
inlineCharacterLimit: 80,
|
|
75
|
+
}).replace('"[form]"', 'form');
|
|
76
|
+
push(`const options = ${optionString};`);
|
|
55
77
|
blank();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
indent: " ",
|
|
65
|
-
inlineCharacterLimit: 80
|
|
66
|
-
}).replace('"[form]"', "form");
|
|
67
|
-
push(`const options = ${optionString};`);
|
|
68
|
-
blank();
|
|
69
|
-
push("try {");
|
|
70
|
-
push("const { data } = await axios.request(options);", 1);
|
|
71
|
-
push("console.log(data);", 1);
|
|
72
|
-
push("} catch (error) {");
|
|
73
|
-
push("console.error(error);", 1);
|
|
74
|
-
push("}");
|
|
75
|
-
return join();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
export {
|
|
79
|
-
axios
|
|
78
|
+
push('try {');
|
|
79
|
+
push('const { data } = await axios.request(options);', 1);
|
|
80
|
+
push('console.log(data);', 1);
|
|
81
|
+
push('} catch (error) {');
|
|
82
|
+
push('console.error(error);', 1);
|
|
83
|
+
push('}');
|
|
84
|
+
return join();
|
|
85
|
+
},
|
|
80
86
|
};
|
|
81
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,74 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
settings
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for native XMLHttpRequest
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @AhmadNassri
|
|
7
|
+
*
|
|
8
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
+
*/
|
|
10
|
+
import stringifyObject from 'stringify-object';
|
|
11
|
+
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
12
|
+
import { getHeader, getHeaderName, hasHeader } from '../../../../httpsnippet-lite/helpers/headers.js';
|
|
13
|
+
export const jquery = {
|
|
14
|
+
info: {
|
|
15
|
+
key: 'jquery',
|
|
16
|
+
title: 'jQuery',
|
|
17
|
+
link: 'http://api.jquery.com/jquery.ajax/',
|
|
18
|
+
description: 'Perform an asynchronous HTTP (Ajax) requests with jQuery',
|
|
19
|
+
},
|
|
20
|
+
convert: ({ fullUrl, method, allHeaders, postData }, options) => {
|
|
21
|
+
let _a;
|
|
22
|
+
const opts = {
|
|
23
|
+
indent: ' ',
|
|
24
|
+
...options,
|
|
25
|
+
};
|
|
26
|
+
const { blank, push, join } = new CodeBuilder({ indent: opts.indent });
|
|
27
|
+
const settings = {
|
|
28
|
+
async: true,
|
|
29
|
+
crossDomain: true,
|
|
30
|
+
url: fullUrl,
|
|
31
|
+
method,
|
|
32
|
+
headers: allHeaders,
|
|
33
|
+
};
|
|
34
|
+
switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
|
|
35
|
+
case 'application/x-www-form-urlencoded':
|
|
36
|
+
settings.data = postData?.paramsObj ? postData.paramsObj : postData.text;
|
|
37
|
+
break;
|
|
38
|
+
case 'application/json':
|
|
39
|
+
settings.processData = false;
|
|
40
|
+
settings.data = postData.text;
|
|
41
|
+
break;
|
|
42
|
+
case 'multipart/form-data':
|
|
43
|
+
if (!postData?.params) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
push('const form = new FormData();');
|
|
47
|
+
postData.params.forEach((param) => {
|
|
48
|
+
push(`form.append('${param.name}', '${param.value || param.fileName || ''}');`);
|
|
49
|
+
});
|
|
50
|
+
settings.processData = false;
|
|
51
|
+
settings.contentType = false;
|
|
52
|
+
settings.mimeType = 'multipart/form-data';
|
|
53
|
+
settings.data = '[form]';
|
|
54
|
+
// remove the contentType header
|
|
55
|
+
if (hasHeader(allHeaders, 'content-type')) {
|
|
56
|
+
if ((_a = getHeader(allHeaders, 'content-type')) === null || _a === void 0 ? void 0 : _a.includes('boundary')) {
|
|
57
|
+
const headerName = getHeaderName(allHeaders, 'content-type');
|
|
58
|
+
if (headerName) {
|
|
59
|
+
delete settings.headers[headerName];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
blank();
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
67
|
+
settings.data = postData.text;
|
|
68
|
+
}
|
|
52
69
|
}
|
|
70
|
+
const stringifiedSettings = stringifyObject(settings, {
|
|
71
|
+
indent: opts.indent,
|
|
72
|
+
}).replace("'[form]'", 'form');
|
|
73
|
+
push(`const settings = ${stringifiedSettings};`);
|
|
53
74
|
blank();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
const stringifiedSettings = stringifyObject(settings, {
|
|
61
|
-
indent: opts.indent
|
|
62
|
-
}).replace("'[form]'", "form");
|
|
63
|
-
push(`const settings = ${stringifiedSettings};`);
|
|
64
|
-
blank();
|
|
65
|
-
push("$.ajax(settings).done(function (response) {");
|
|
66
|
-
push("console.log(response);", 1);
|
|
67
|
-
push("});");
|
|
68
|
-
return join();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
export {
|
|
72
|
-
jquery
|
|
75
|
+
push('$.ajax(settings).done(function (response) {');
|
|
76
|
+
push('console.log(response);', 1);
|
|
77
|
+
push('});');
|
|
78
|
+
return join();
|
|
79
|
+
},
|
|
73
80
|
};
|
|
74
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,76 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
indent:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for native XMLHttpRequest
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @AhmadNassri
|
|
7
|
+
*
|
|
8
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
+
*/
|
|
10
|
+
import stringifyObject from 'stringify-object';
|
|
11
|
+
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
12
|
+
import { escapeForSingleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
|
|
13
|
+
import { getHeader, getHeaderName, hasHeader } from '../../../../httpsnippet-lite/helpers/headers.js';
|
|
14
|
+
export const xhr = {
|
|
15
|
+
info: {
|
|
16
|
+
key: 'xhr',
|
|
17
|
+
title: 'XMLHttpRequest',
|
|
18
|
+
link: 'https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest',
|
|
19
|
+
description: 'W3C Standard API that provides scripted client functionality',
|
|
20
|
+
},
|
|
21
|
+
convert: ({ postData, allHeaders, method, fullUrl }, options) => {
|
|
22
|
+
let _a;
|
|
23
|
+
const opts = {
|
|
24
|
+
indent: ' ',
|
|
25
|
+
cors: true,
|
|
26
|
+
...options,
|
|
27
|
+
};
|
|
28
|
+
const { blank, push, join } = new CodeBuilder({ indent: opts.indent });
|
|
29
|
+
switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
|
|
30
|
+
case 'application/json':
|
|
31
|
+
push(`const data = JSON.stringify(${stringifyObject(postData?.jsonObj, {
|
|
32
|
+
indent: opts.indent,
|
|
33
|
+
})});`);
|
|
34
|
+
blank();
|
|
35
|
+
break;
|
|
36
|
+
case 'multipart/form-data':
|
|
37
|
+
if (!postData?.params) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
push('const data = new FormData();');
|
|
41
|
+
postData.params.forEach((param) => {
|
|
42
|
+
push(`data.append('${param.name}', '${param.value || param.fileName || ''}');`);
|
|
43
|
+
});
|
|
44
|
+
// remove the contentType header
|
|
45
|
+
if (hasHeader(allHeaders, 'content-type')) {
|
|
46
|
+
if ((_a = getHeader(allHeaders, 'content-type')) === null || _a === void 0 ? void 0 : _a.includes('boundary')) {
|
|
47
|
+
const headerName = getHeaderName(allHeaders, 'content-type');
|
|
48
|
+
if (headerName) {
|
|
49
|
+
delete allHeaders[headerName];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
blank();
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
push(`const data = ${(postData === null || postData === void 0 ? void 0 : postData.text) ? `'${postData.text}'` : 'null'};`);
|
|
57
|
+
blank();
|
|
32
58
|
}
|
|
33
|
-
push(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
if (hasHeader(allHeaders, "content-type")) {
|
|
38
|
-
if ((_a = getHeader(allHeaders, "content-type")) === null || _a === void 0 ? void 0 : _a.includes("boundary")) {
|
|
39
|
-
const headerName = getHeaderName(allHeaders, "content-type");
|
|
40
|
-
if (headerName) {
|
|
41
|
-
delete allHeaders[headerName];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
59
|
+
push('const xhr = new XMLHttpRequest();');
|
|
60
|
+
if (opts.cors) {
|
|
61
|
+
push('xhr.withCredentials = true;');
|
|
44
62
|
}
|
|
45
63
|
blank();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
push(
|
|
49
|
-
|
|
50
|
-
);
|
|
64
|
+
push("xhr.addEventListener('readystatechange', function () {");
|
|
65
|
+
push('if (this.readyState === this.DONE) {', 1);
|
|
66
|
+
push('console.log(this.responseText);', 2);
|
|
67
|
+
push('}', 1);
|
|
68
|
+
push('});');
|
|
51
69
|
blank();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
push("console.log(this.responseText);", 2);
|
|
61
|
-
push("}", 1);
|
|
62
|
-
push("});");
|
|
63
|
-
blank();
|
|
64
|
-
push(`xhr.open('${method}', '${fullUrl}');`);
|
|
65
|
-
Object.keys(allHeaders).forEach((key) => {
|
|
66
|
-
push(`xhr.setRequestHeader('${key}', '${escapeForSingleQuotes(allHeaders[key])}');`);
|
|
67
|
-
});
|
|
68
|
-
blank();
|
|
69
|
-
push("xhr.send(data);");
|
|
70
|
-
return join();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
export {
|
|
74
|
-
xhr
|
|
70
|
+
push(`xhr.open('${method}', '${fullUrl}');`);
|
|
71
|
+
Object.keys(allHeaders).forEach((key) => {
|
|
72
|
+
push(`xhr.setRequestHeader('${key}', '${escapeForSingleQuotes(allHeaders[key])}');`);
|
|
73
|
+
});
|
|
74
|
+
blank();
|
|
75
|
+
push('xhr.send(data);');
|
|
76
|
+
return join();
|
|
77
|
+
},
|
|
75
78
|
};
|
|
76
|
-
//# sourceMappingURL=client.js.map
|