@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,153 +1,157 @@
|
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
imports.add("strings");
|
|
72
|
-
push("postData := url.Values{}", indent);
|
|
73
|
-
postData.params.forEach((param) => {
|
|
74
|
-
push(`postData.Set("${param.name}", "${escapeForDoubleQuotes(param.value)}")`, indent);
|
|
75
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for native Go.
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @montanaflynn
|
|
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 native = {
|
|
13
|
+
info: {
|
|
14
|
+
key: 'native',
|
|
15
|
+
title: 'NewRequest',
|
|
16
|
+
link: 'http://golang.org/pkg/net/http/#NewRequest',
|
|
17
|
+
description: 'Golang HTTP client request',
|
|
18
|
+
},
|
|
19
|
+
convert: ({ postData, method, allHeaders, fullUrl }, options = {}) => {
|
|
20
|
+
const { blank, push, join, addPostProcessor } = new CodeBuilder({ indent: '\t' });
|
|
21
|
+
const { showBoilerplate = true, checkErrors = false, printBody = true, timeout = -1, insecureSkipVerify = false, } = options;
|
|
22
|
+
const errorPlaceholder = checkErrors ? 'err' : '_';
|
|
23
|
+
const indent = showBoilerplate ? 1 : 0;
|
|
24
|
+
const errorCheck = () => {
|
|
25
|
+
if (checkErrors) {
|
|
26
|
+
push('if err != nil {', indent);
|
|
27
|
+
push('panic(err)', indent + 1);
|
|
28
|
+
push('}', indent);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
// Create boilerplate
|
|
32
|
+
const imports = new Set();
|
|
33
|
+
if (showBoilerplate) {
|
|
34
|
+
push('package main');
|
|
35
|
+
blank();
|
|
36
|
+
push('import ()');
|
|
37
|
+
addPostProcessor((code) => {
|
|
38
|
+
const importArray = [...imports];
|
|
39
|
+
importArray.sort();
|
|
40
|
+
const importBlock = importArray.map((line) => `\t"${line}"`).join('\n');
|
|
41
|
+
return code.replace(/import \(\)/, `import (\n${importBlock}\n)`);
|
|
42
|
+
});
|
|
43
|
+
imports.add('fmt');
|
|
44
|
+
imports.add('net/http');
|
|
45
|
+
blank();
|
|
46
|
+
push('func main() {');
|
|
47
|
+
}
|
|
48
|
+
// Create an insecure transport for the client
|
|
49
|
+
if (insecureSkipVerify) {
|
|
50
|
+
imports.add('crypto/tls');
|
|
51
|
+
push('insecureTransport := http.DefaultTransport.(*http.Transport).Clone()', indent);
|
|
52
|
+
push('insecureTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}', indent);
|
|
53
|
+
}
|
|
54
|
+
// Create client
|
|
55
|
+
const hasTimeout = timeout > 0;
|
|
56
|
+
const hasClient = hasTimeout || insecureSkipVerify;
|
|
57
|
+
const client = hasClient ? 'client' : 'http.DefaultClient';
|
|
58
|
+
if (hasClient) {
|
|
59
|
+
push('client := http.Client{', indent);
|
|
60
|
+
if (hasTimeout) {
|
|
61
|
+
imports.add('time');
|
|
62
|
+
push(`Timeout: time.Duration(${timeout} * time.Second),`, indent + 1);
|
|
63
|
+
}
|
|
64
|
+
if (insecureSkipVerify) {
|
|
65
|
+
push('Transport: insecureTransport,', indent + 1);
|
|
66
|
+
}
|
|
67
|
+
push('}', indent);
|
|
68
|
+
blank();
|
|
69
|
+
}
|
|
70
|
+
push(`url := "${fullUrl}"`, indent);
|
|
76
71
|
blank();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
72
|
+
// If we have body content or not create the var and reader or nil
|
|
73
|
+
if (postData !== null && postData !== void 0 && (postData.params || postData.text)) {
|
|
74
|
+
if (postData.mimeType === 'application/x-www-form-urlencoded' && postData.params) {
|
|
75
|
+
imports.add('net/url');
|
|
76
|
+
imports.add('strings');
|
|
77
|
+
push('postData := url.Values{}', indent);
|
|
78
|
+
postData.params.forEach((param) => {
|
|
79
|
+
push(`postData.Set("${param.name}", "${escapeForDoubleQuotes(param.value)}")`, indent);
|
|
80
|
+
});
|
|
81
|
+
blank();
|
|
82
|
+
push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, strings.NewReader(postData.Encode()))`, indent);
|
|
83
|
+
}
|
|
84
|
+
else if (postData.mimeType === 'multipart/form-data' && postData.params) {
|
|
85
|
+
imports.add('bytes');
|
|
86
|
+
imports.add('mime/multipart');
|
|
87
|
+
push('payload := &bytes.Buffer{}', indent);
|
|
88
|
+
push('writer := multipart.NewWriter(payload)', indent);
|
|
89
|
+
postData.params.forEach((param) => {
|
|
90
|
+
blank();
|
|
91
|
+
if (param.fileName) {
|
|
92
|
+
push(`part, ${errorPlaceholder} := writer.CreateFormFile("${param.name}", "${param.fileName}")`, indent);
|
|
93
|
+
errorCheck();
|
|
94
|
+
blank();
|
|
95
|
+
push(`f, ${errorPlaceholder} := os.Open("${param.fileName}")`, indent);
|
|
96
|
+
errorCheck();
|
|
97
|
+
push('defer f.Close()', indent);
|
|
98
|
+
blank();
|
|
99
|
+
push(`_, ${errorPlaceholder} = io.Copy(part, f)`, indent);
|
|
100
|
+
errorCheck();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
push(`${errorPlaceholder} = writer.WriteField("${param.name}", "${escapeForDoubleQuotes(param.value)}")`, indent);
|
|
104
|
+
errorCheck();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
push('writer.Close()', indent);
|
|
108
|
+
blank();
|
|
109
|
+
push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, payload)`, indent);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
imports.add('strings');
|
|
113
|
+
push(`payload := strings.NewReader(${JSON.stringify(postData.text)})`, indent);
|
|
114
|
+
blank();
|
|
115
|
+
push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, payload)`, indent);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, nil)`, indent);
|
|
120
|
+
}
|
|
121
|
+
errorCheck();
|
|
122
|
+
blank();
|
|
123
|
+
// Add headers
|
|
124
|
+
if (postData !== null && postData !== void 0 && postData.mimeType === 'multipart/form-data' && postData.params) {
|
|
125
|
+
push(`req.Header.Set("Content-Type", writer.FormDataContentType())`, indent);
|
|
126
|
+
}
|
|
127
|
+
if (Object.keys(allHeaders).length) {
|
|
128
|
+
Object.keys(allHeaders).forEach((key) => {
|
|
129
|
+
push(`req.Header.Add("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, indent);
|
|
130
|
+
});
|
|
91
131
|
blank();
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
132
|
+
}
|
|
133
|
+
// Make request
|
|
134
|
+
push(`res, ${errorPlaceholder} := ${client}.Do(req)`, indent);
|
|
135
|
+
errorCheck();
|
|
136
|
+
// Get Body
|
|
137
|
+
if (printBody) {
|
|
138
|
+
imports.add('io');
|
|
95
139
|
blank();
|
|
96
|
-
push(
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
push(
|
|
100
|
-
`${errorPlaceholder} = writer.WriteField("${param.name}", "${escapeForDoubleQuotes(param.value)}")`,
|
|
101
|
-
indent
|
|
102
|
-
);
|
|
140
|
+
push('defer res.Body.Close()', indent);
|
|
141
|
+
push(`body, ${errorPlaceholder} := io.ReadAll(res.Body)`, indent);
|
|
103
142
|
errorCheck();
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
push("writer.Close()", indent);
|
|
107
|
-
blank();
|
|
108
|
-
push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, payload)`, indent);
|
|
109
|
-
} else {
|
|
110
|
-
imports.add("strings");
|
|
111
|
-
push(`payload := strings.NewReader(${JSON.stringify(postData.text)})`, indent);
|
|
143
|
+
}
|
|
144
|
+
// Print it
|
|
112
145
|
blank();
|
|
113
|
-
push(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
Object.keys(allHeaders).forEach((key) => {
|
|
125
|
-
push(`req.Header.Add("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, indent);
|
|
126
|
-
});
|
|
127
|
-
blank();
|
|
128
|
-
}
|
|
129
|
-
push(`res, ${errorPlaceholder} := ${client}.Do(req)`, indent);
|
|
130
|
-
errorCheck();
|
|
131
|
-
if (printBody) {
|
|
132
|
-
imports.add("io");
|
|
133
|
-
blank();
|
|
134
|
-
push("defer res.Body.Close()", indent);
|
|
135
|
-
push(`body, ${errorPlaceholder} := io.ReadAll(res.Body)`, indent);
|
|
136
|
-
errorCheck();
|
|
137
|
-
}
|
|
138
|
-
blank();
|
|
139
|
-
push("fmt.Println(res)", indent);
|
|
140
|
-
if (printBody) {
|
|
141
|
-
push("fmt.Println(string(body))", indent);
|
|
142
|
-
}
|
|
143
|
-
if (showBoilerplate) {
|
|
144
|
-
blank();
|
|
145
|
-
push("}");
|
|
146
|
-
}
|
|
147
|
-
return join();
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
export {
|
|
151
|
-
native
|
|
146
|
+
push('fmt.Println(res)', indent);
|
|
147
|
+
if (printBody) {
|
|
148
|
+
push('fmt.Println(string(body))', indent);
|
|
149
|
+
}
|
|
150
|
+
// End main block
|
|
151
|
+
if (showBoilerplate) {
|
|
152
|
+
blank();
|
|
153
|
+
push('}');
|
|
154
|
+
}
|
|
155
|
+
return join();
|
|
156
|
+
},
|
|
152
157
|
};
|
|
153
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
import { CodeBuilder } from
|
|
2
|
-
import { escapeForDoubleQuotes } from
|
|
3
|
-
const asynchttp = {
|
|
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
|
-
|
|
1
|
+
import { CodeBuilder } from '../../../helpers/code-builder.js';
|
|
2
|
+
import { escapeForDoubleQuotes } from '../../../helpers/escape.js';
|
|
3
|
+
export const asynchttp = {
|
|
4
|
+
info: {
|
|
5
|
+
key: 'asynchttp',
|
|
6
|
+
title: 'AsyncHttp',
|
|
7
|
+
link: 'https://github.com/AsyncHttpClient/async-http-client',
|
|
8
|
+
description: 'Asynchronous Http and WebSocket Client library for Java',
|
|
9
|
+
},
|
|
10
|
+
convert: ({ method, allHeaders, postData, fullUrl }, options) => {
|
|
11
|
+
const opts = {
|
|
12
|
+
indent: ' ',
|
|
13
|
+
...options,
|
|
14
|
+
};
|
|
15
|
+
const { blank, push, join } = new CodeBuilder({ indent: opts.indent });
|
|
16
|
+
push('AsyncHttpClient client = new DefaultAsyncHttpClient();');
|
|
17
|
+
push(`client.prepare("${method.toUpperCase()}", "${fullUrl}")`);
|
|
18
|
+
// Add headers, including the cookies
|
|
19
|
+
Object.keys(allHeaders).forEach((key) => {
|
|
20
|
+
push(`.setHeader("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
|
|
21
|
+
});
|
|
22
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
23
|
+
push(`.setBody(${JSON.stringify(postData.text)})`, 1);
|
|
24
|
+
}
|
|
25
|
+
push('.execute()', 1);
|
|
26
|
+
push('.toCompletableFuture()', 1);
|
|
27
|
+
push('.thenAccept(System.out::println)', 1);
|
|
28
|
+
push('.join();', 1);
|
|
29
|
+
blank();
|
|
30
|
+
push('client.close();');
|
|
31
|
+
return join();
|
|
32
|
+
},
|
|
32
33
|
};
|
|
33
|
-
export {
|
|
34
|
-
asynchttp
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,40 +1,41 @@
|
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for Java using java.net.http.
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @wtetsu
|
|
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 nethttp = {
|
|
13
|
+
info: {
|
|
14
|
+
key: 'nethttp',
|
|
15
|
+
title: 'java.net.http',
|
|
16
|
+
link: 'https://openjdk.java.net/groups/net/httpclient/intro.html',
|
|
17
|
+
description: 'Java Standardized HTTP Client API',
|
|
18
|
+
},
|
|
19
|
+
convert: ({ allHeaders, fullUrl, method, postData }, options) => {
|
|
20
|
+
const opts = {
|
|
21
|
+
indent: ' ',
|
|
22
|
+
...options,
|
|
23
|
+
};
|
|
24
|
+
const { push, join } = new CodeBuilder({ indent: opts.indent });
|
|
25
|
+
push('HttpRequest request = HttpRequest.newBuilder()');
|
|
26
|
+
push(`.uri(URI.create("${fullUrl}"))`, 2);
|
|
27
|
+
Object.keys(allHeaders).forEach((key) => {
|
|
28
|
+
push(`.header("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 2);
|
|
29
|
+
});
|
|
30
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
31
|
+
push(`.method("${method.toUpperCase()}", HttpRequest.BodyPublishers.ofString(${JSON.stringify(postData.text)}))`, 2);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
push(`.method("${method.toUpperCase()}", HttpRequest.BodyPublishers.noBody())`, 2);
|
|
35
|
+
}
|
|
36
|
+
push('.build();', 2);
|
|
37
|
+
push('HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());');
|
|
38
|
+
push('System.out.println(response.body());');
|
|
39
|
+
return join();
|
|
40
|
+
},
|
|
36
41
|
};
|
|
37
|
-
export {
|
|
38
|
-
nethttp
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,77 +1,87 @@
|
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for Java using OkHttp.
|
|
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 okhttp = {
|
|
13
|
+
info: {
|
|
14
|
+
key: 'okhttp',
|
|
15
|
+
title: 'OkHttp',
|
|
16
|
+
link: 'http://square.github.io/okhttp/',
|
|
17
|
+
description: 'An HTTP Request Client Library',
|
|
18
|
+
},
|
|
19
|
+
convert: ({ postData, method, fullUrl, allHeaders }, options) => {
|
|
20
|
+
const opts = {
|
|
21
|
+
indent: ' ',
|
|
22
|
+
...options,
|
|
23
|
+
};
|
|
24
|
+
const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
|
|
25
|
+
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'];
|
|
26
|
+
const methodsWithBody = ['POST', 'PUT', 'DELETE', 'PATCH'];
|
|
27
|
+
push('OkHttpClient client = new OkHttpClient();');
|
|
27
28
|
blank();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
if (postData !== null && postData !== void 0) {
|
|
30
|
+
if (postData.mimeType === 'application/x-www-form-urlencoded' && postData.params) {
|
|
31
|
+
push('FormBody formBody = new FormBody.Builder()');
|
|
32
|
+
postData.params.forEach((param) => {
|
|
33
|
+
push(`.addEncoded("${param.name}", "${param.value}")`, 1);
|
|
34
|
+
});
|
|
35
|
+
push('.build();', 1);
|
|
36
|
+
blank();
|
|
37
|
+
}
|
|
38
|
+
else if (postData.mimeType === 'multipart/form-data' && postData.params) {
|
|
39
|
+
push('MultipartBody body = new MultipartBody.Builder()');
|
|
40
|
+
push('.setType(MultipartBody.FORM)', 1);
|
|
41
|
+
postData.params.forEach((param) => {
|
|
42
|
+
if (param.fileName !== undefined) {
|
|
43
|
+
push(`.addFormDataPart("${param.name}", "${param.fileName}", RequestBody.create(MediaType.parse("application/octet-stream"), new File("${param.fileName}")))`, 1);
|
|
44
|
+
}
|
|
45
|
+
else if (param.value !== undefined) {
|
|
46
|
+
push(`.addFormDataPart("${param.name}", "${param.value}")`, 1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
push('.build();', 1);
|
|
50
|
+
blank();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
push(`MediaType mediaType = MediaType.parse("${postData.mimeType}");`);
|
|
54
|
+
push(`RequestBody body = RequestBody.create(mediaType, ${JSON.stringify(postData.text)});`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
push('Request request = new Request.Builder()');
|
|
58
|
+
push(`.url("${fullUrl}")`, 1);
|
|
59
|
+
if (!methods.includes(method.toUpperCase())) {
|
|
60
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
61
|
+
push(`.method("${method.toUpperCase()}", body)`, 1);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
push(`.method("${method.toUpperCase()}", null)`, 1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (methodsWithBody.includes(method.toUpperCase())) {
|
|
68
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text || postData.params) {
|
|
69
|
+
push(`.${method.toLowerCase()}(body)`, 1);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
push(`.${method.toLowerCase()}(null)`, 1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
push(`.${method.toLowerCase()}()`, 1);
|
|
77
|
+
}
|
|
78
|
+
// Add headers, including the cookies
|
|
79
|
+
Object.keys(allHeaders).forEach((key) => {
|
|
80
|
+
push(`.addHeader("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
|
|
40
81
|
});
|
|
41
|
-
push(
|
|
82
|
+
push('.build();', 1);
|
|
42
83
|
blank();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
push("Request request = new Request.Builder()");
|
|
49
|
-
push(`.url("${fullUrl}")`, 1);
|
|
50
|
-
if (!methods.includes(method.toUpperCase())) {
|
|
51
|
-
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
52
|
-
push(`.method("${method.toUpperCase()}", body)`, 1);
|
|
53
|
-
} else {
|
|
54
|
-
push(`.method("${method.toUpperCase()}", null)`, 1);
|
|
55
|
-
}
|
|
56
|
-
} else if (methodsWithBody.includes(method.toUpperCase())) {
|
|
57
|
-
if (postData === null || postData === void 0 ? void 0 : postData.text || postData.params) {
|
|
58
|
-
push(`.${method.toLowerCase()}(body)`, 1);
|
|
59
|
-
} else {
|
|
60
|
-
push(`.${method.toLowerCase()}(null)`, 1);
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
push(`.${method.toLowerCase()}()`, 1);
|
|
64
|
-
}
|
|
65
|
-
Object.keys(allHeaders).forEach((key) => {
|
|
66
|
-
push(`.addHeader("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
|
|
67
|
-
});
|
|
68
|
-
push(".build();", 1);
|
|
69
|
-
blank();
|
|
70
|
-
push("Response response = client.newCall(request).execute();");
|
|
71
|
-
return join();
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
export {
|
|
75
|
-
okhttp
|
|
84
|
+
push('Response response = client.newCall(request).execute();');
|
|
85
|
+
return join();
|
|
86
|
+
},
|
|
76
87
|
};
|
|
77
|
-
//# sourceMappingURL=client.js.map
|