@scalar/snippetz 0.7.4 → 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,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Given a headers object retrieve a specific header out of it via a case-insensitive key.
|
|
3
|
+
*/
|
|
4
|
+
export const getHeaderName = (headers, name) => Object.keys(headers).find((header) => header.toLowerCase() === name.toLowerCase());
|
|
5
|
+
/**
|
|
6
|
+
* Given a headers object retrieve the contents of a header out of it via a case-insensitive key.
|
|
7
|
+
*/
|
|
8
|
+
export const getHeader = (headers, name) => {
|
|
9
|
+
const headerName = getHeaderName(headers, name);
|
|
10
|
+
if (!headerName) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return headers[headerName];
|
|
8
14
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
hasHeader
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=headers.js.map
|
|
15
|
+
/**
|
|
16
|
+
* Determine if a given case-insensitive header exists within a header object.
|
|
17
|
+
*/
|
|
18
|
+
export const hasHeader = (headers, name) => Boolean(getHeaderName(headers, name));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Use 'strong quoting' using single quotes so that we only need to deal with nested single quote characters.
|
|
3
|
+
* see: http://wiki.bash-hackers.org/syntax/quoting#strong_quoting
|
|
4
|
+
*/
|
|
5
|
+
export const shellQuote = (value = '') => {
|
|
6
|
+
const safe = /^[a-z0-9-_/.@%^=:]+$/i;
|
|
7
|
+
const isShellSafe = safe.test(value);
|
|
8
|
+
if (isShellSafe) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
// if the value is not shell safe, then quote it
|
|
12
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
8
13
|
};
|
|
9
|
-
const shellEscape = (value) => value.replace(/\r/g,
|
|
10
|
-
export {
|
|
11
|
-
shellEscape,
|
|
12
|
-
shellQuote
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=shell.js.map
|
|
14
|
+
export const shellEscape = (value) => value.replace(/\r/g, '\\r').replace(/\n/g, '\\n');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1,70 +1,72 @@
|
|
|
1
|
-
import { CodeBuilder } from
|
|
2
|
-
import { escapeForDoubleQuotes } from
|
|
3
|
-
import { createSearchParams } from
|
|
4
|
-
const libcurl = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
2
|
+
import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
|
|
3
|
+
import { createSearchParams } from '../../../../libs/http.js';
|
|
4
|
+
export const libcurl = {
|
|
5
|
+
info: {
|
|
6
|
+
key: 'libcurl',
|
|
7
|
+
title: 'Libcurl',
|
|
8
|
+
link: 'http://curl.haxx.se/libcurl',
|
|
9
|
+
description: 'Simple REST and HTTP API Client for C',
|
|
10
|
+
},
|
|
11
|
+
convert: ({ method, fullUrl, headersObj, allHeaders, postData }) => {
|
|
12
|
+
const { push, blank, join } = new CodeBuilder({ indent: ' ' });
|
|
13
|
+
push('CURL *hnd = curl_easy_init();');
|
|
14
|
+
blank();
|
|
15
|
+
push(`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method.toUpperCase()}");`);
|
|
16
|
+
push(`curl_easy_setopt(hnd, CURLOPT_URL, "${fullUrl}");`);
|
|
17
|
+
// Add headers, including the cookies
|
|
18
|
+
const headers = Object.keys(headersObj);
|
|
19
|
+
// construct headers
|
|
20
|
+
if (headers.length) {
|
|
21
|
+
blank();
|
|
22
|
+
push('struct curl_slist *headers = NULL;');
|
|
23
|
+
headers.forEach((header) => {
|
|
24
|
+
// See https://curl.se/libcurl/c/httpcustomheader.html for syntax
|
|
25
|
+
if (headersObj[header]) {
|
|
26
|
+
push(`headers = curl_slist_append(headers, "${header}: ${escapeForDoubleQuotes(headersObj[header])}");`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
push(`headers = curl_slist_append(headers, "${header};");`);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);');
|
|
33
|
+
}
|
|
34
|
+
// construct cookies
|
|
35
|
+
if (allHeaders.cookie) {
|
|
36
|
+
blank();
|
|
37
|
+
push(`curl_easy_setopt(hnd, CURLOPT_COOKIE, "${allHeaders.cookie}");`);
|
|
38
|
+
}
|
|
39
|
+
if (postData !== null && postData !== void 0) {
|
|
40
|
+
blank();
|
|
41
|
+
if (postData.text) {
|
|
42
|
+
push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${JSON.stringify(postData.text)});`);
|
|
43
|
+
}
|
|
44
|
+
else if (postData.mimeType === 'application/x-www-form-urlencoded' && postData.params) {
|
|
45
|
+
push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "${createSearchParams(postData.params).toString()}");`);
|
|
46
|
+
}
|
|
47
|
+
else if (postData.mimeType === 'multipart/form-data' && postData.params) {
|
|
48
|
+
push('curl_mime *mime = curl_mime_init(hnd);');
|
|
49
|
+
postData.params.forEach((param) => {
|
|
50
|
+
blank();
|
|
51
|
+
push('{');
|
|
52
|
+
push('curl_mimepart *part = curl_mime_addpart(mime);', 1);
|
|
53
|
+
if (param.name) {
|
|
54
|
+
push(`curl_mime_name(part, "${param.name}");`, 1);
|
|
55
|
+
}
|
|
56
|
+
if (param.fileName) {
|
|
57
|
+
push(`curl_mime_filedata(part, "${param.fileName}");`, 1);
|
|
58
|
+
}
|
|
59
|
+
else if (param.value) {
|
|
60
|
+
push(`curl_mime_data(part, "${escapeForDoubleQuotes(param.value)}", CURL_ZERO_TERMINATED);`, 1);
|
|
61
|
+
}
|
|
62
|
+
push('}');
|
|
63
|
+
});
|
|
64
|
+
blank();
|
|
65
|
+
push('curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime);');
|
|
66
|
+
}
|
|
28
67
|
}
|
|
29
|
-
});
|
|
30
|
-
push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);");
|
|
31
|
-
}
|
|
32
|
-
if (allHeaders.cookie) {
|
|
33
|
-
blank();
|
|
34
|
-
push(`curl_easy_setopt(hnd, CURLOPT_COOKIE, "${allHeaders.cookie}");`);
|
|
35
|
-
}
|
|
36
|
-
if (postData !== null && postData !== void 0) {
|
|
37
|
-
blank();
|
|
38
|
-
if (postData.text) {
|
|
39
|
-
push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${JSON.stringify(postData.text)});`);
|
|
40
|
-
} else if (postData.mimeType === "application/x-www-form-urlencoded" && postData.params) {
|
|
41
|
-
push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "${createSearchParams(postData.params).toString()}");`);
|
|
42
|
-
} else if (postData.mimeType === "multipart/form-data" && postData.params) {
|
|
43
|
-
push("curl_mime *mime = curl_mime_init(hnd);");
|
|
44
|
-
postData.params.forEach((param) => {
|
|
45
|
-
blank();
|
|
46
|
-
push("{");
|
|
47
|
-
push("curl_mimepart *part = curl_mime_addpart(mime);", 1);
|
|
48
|
-
if (param.name) {
|
|
49
|
-
push(`curl_mime_name(part, "${param.name}");`, 1);
|
|
50
|
-
}
|
|
51
|
-
if (param.fileName) {
|
|
52
|
-
push(`curl_mime_filedata(part, "${param.fileName}");`, 1);
|
|
53
|
-
} else if (param.value) {
|
|
54
|
-
push(`curl_mime_data(part, "${escapeForDoubleQuotes(param.value)}", CURL_ZERO_TERMINATED);`, 1);
|
|
55
|
-
}
|
|
56
|
-
push("}");
|
|
57
|
-
});
|
|
58
68
|
blank();
|
|
59
|
-
push(
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
blank();
|
|
63
|
-
push("CURLcode ret = curl_easy_perform(hnd);");
|
|
64
|
-
return join();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
export {
|
|
68
|
-
libcurl
|
|
69
|
+
push('CURLcode ret = curl_easy_perform(hnd);');
|
|
70
|
+
return join();
|
|
71
|
+
},
|
|
69
72
|
};
|
|
70
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,175 +1,186 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for Clojure using clj-http.
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @tggreene
|
|
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 { getHeader, getHeaderName } from '../../../../httpsnippet-lite/helpers/headers.js';
|
|
3
12
|
class Keyword {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
name;
|
|
14
|
+
toString;
|
|
15
|
+
constructor(name) {
|
|
16
|
+
this.name = '';
|
|
17
|
+
this.toString = () => `:${this.name}`;
|
|
18
|
+
this.name = name;
|
|
19
|
+
}
|
|
11
20
|
}
|
|
12
21
|
class File {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
path;
|
|
23
|
+
toString;
|
|
24
|
+
constructor(path) {
|
|
25
|
+
this.path = '';
|
|
26
|
+
this.toString = () => `(clojure.java.io/file "${this.path}")`;
|
|
27
|
+
this.path = path;
|
|
28
|
+
}
|
|
20
29
|
}
|
|
21
30
|
const jsType = (input) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
if (input === undefined) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (input === null) {
|
|
35
|
+
return 'null';
|
|
36
|
+
}
|
|
37
|
+
return input.constructor.name.toLowerCase();
|
|
29
38
|
};
|
|
30
39
|
const objEmpty = (input) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
if (jsType(input) === 'object') {
|
|
41
|
+
return Object.keys(input).length === 0;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
35
44
|
};
|
|
36
45
|
const filterEmpty = (input) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
Object.keys(input)
|
|
47
|
+
.filter((x) => objEmpty(input[x]))
|
|
48
|
+
.forEach((x) => {
|
|
49
|
+
delete input[x];
|
|
50
|
+
});
|
|
51
|
+
return input;
|
|
41
52
|
};
|
|
42
53
|
const padBlock = (padSize, input) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
${padding}`);
|
|
54
|
+
const padding = ' '.repeat(padSize);
|
|
55
|
+
return input.replace(/\n/g, `\n${padding}`);
|
|
46
56
|
};
|
|
47
57
|
const jsToEdn = (js) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
switch (jsType(js)) {
|
|
59
|
+
case 'string':
|
|
60
|
+
return `"${js.replace(/"/g, '\\"')}"`;
|
|
61
|
+
case 'file':
|
|
62
|
+
return js.toString();
|
|
63
|
+
case 'keyword':
|
|
64
|
+
return js.toString();
|
|
65
|
+
case 'null':
|
|
66
|
+
return 'nil';
|
|
67
|
+
case 'regexp':
|
|
68
|
+
return `#"${js.source}"`;
|
|
69
|
+
case 'object': {
|
|
70
|
+
// simple vertical format
|
|
71
|
+
const obj = Object.keys(js)
|
|
72
|
+
.reduce((accumulator, key) => {
|
|
73
|
+
const val = padBlock(key.length + 2, jsToEdn(js[key]));
|
|
74
|
+
return `${accumulator}:${key} ${val}\n `;
|
|
75
|
+
}, '')
|
|
76
|
+
.trim();
|
|
77
|
+
return `{${padBlock(1, obj)}}`;
|
|
78
|
+
}
|
|
79
|
+
case 'array': {
|
|
80
|
+
// simple horizontal format
|
|
81
|
+
const arr = js.reduce((accumulator, value) => `${accumulator} ${jsToEdn(value)}`, '').trim();
|
|
82
|
+
return `[${padBlock(1, arr)}]`;
|
|
83
|
+
}
|
|
84
|
+
default: // 'number' 'boolean'
|
|
85
|
+
return js.toString();
|
|
70
86
|
}
|
|
71
|
-
default:
|
|
72
|
-
return js.toString();
|
|
73
|
-
}
|
|
74
87
|
};
|
|
75
|
-
const clj_http = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
const params = {
|
|
93
|
-
"headers": allHeaders,
|
|
94
|
-
"query-params": queryObj
|
|
95
|
-
};
|
|
96
|
-
if (queryObj && Object.keys(queryObj).length > 0) {
|
|
97
|
-
url = url.split("?")[0];
|
|
98
|
-
}
|
|
99
|
-
switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
|
|
100
|
-
case "application/json":
|
|
101
|
-
{
|
|
102
|
-
params["content-type"] = new Keyword("json");
|
|
103
|
-
params["form-params"] = postData.jsonObj;
|
|
104
|
-
const header = getHeaderName(params.headers, "content-type");
|
|
105
|
-
if (header) {
|
|
106
|
-
delete params.headers[header];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
break;
|
|
110
|
-
case "application/x-www-form-urlencoded":
|
|
111
|
-
{
|
|
112
|
-
params["form-params"] = postData.paramsObj;
|
|
113
|
-
const header = getHeaderName(params.headers, "content-type");
|
|
114
|
-
if (header) {
|
|
115
|
-
delete params.headers[header];
|
|
116
|
-
}
|
|
88
|
+
export const clj_http = {
|
|
89
|
+
info: {
|
|
90
|
+
key: 'clj_http',
|
|
91
|
+
title: 'clj-http',
|
|
92
|
+
link: 'https://github.com/dakrone/clj-http',
|
|
93
|
+
description: 'An idiomatic clojure http client wrapping the apache client.',
|
|
94
|
+
},
|
|
95
|
+
convert: ({ queryObj, method, postData, url, allHeaders }, options) => {
|
|
96
|
+
const { push, join } = new CodeBuilder({
|
|
97
|
+
indent: options === null || options === void 0 ? void 0 : options.indent,
|
|
98
|
+
});
|
|
99
|
+
const methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
100
|
+
method = method.toLowerCase();
|
|
101
|
+
if (!methods.includes(method)) {
|
|
102
|
+
push('Method not supported');
|
|
103
|
+
return join();
|
|
117
104
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
105
|
+
const params = {
|
|
106
|
+
'headers': allHeaders,
|
|
107
|
+
'query-params': queryObj,
|
|
108
|
+
};
|
|
109
|
+
// Remove query string from URL if queryObj has parameters
|
|
110
|
+
if (queryObj && Object.keys(queryObj).length > 0) {
|
|
111
|
+
url = url.split('?')[0];
|
|
126
112
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
113
|
+
switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
|
|
114
|
+
case 'application/json':
|
|
115
|
+
{
|
|
116
|
+
params['content-type'] = new Keyword('json');
|
|
117
|
+
params['form-params'] = postData.jsonObj;
|
|
118
|
+
const header = getHeaderName(params.headers, 'content-type');
|
|
119
|
+
if (header) {
|
|
120
|
+
delete params.headers[header];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case 'application/x-www-form-urlencoded':
|
|
125
|
+
{
|
|
126
|
+
params['form-params'] = postData.paramsObj;
|
|
127
|
+
const header = getHeaderName(params.headers, 'content-type');
|
|
128
|
+
if (header) {
|
|
129
|
+
delete params.headers[header];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case 'text/plain':
|
|
134
|
+
{
|
|
135
|
+
params.body = postData.text;
|
|
136
|
+
const header = getHeaderName(params.headers, 'content-type');
|
|
137
|
+
if (header) {
|
|
138
|
+
delete params.headers[header];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
case 'multipart/form-data': {
|
|
143
|
+
if (postData?.params) {
|
|
144
|
+
params.multipart = postData.params.map((param) => {
|
|
145
|
+
if (param.fileName && !param.value) {
|
|
146
|
+
return {
|
|
147
|
+
name: param.name,
|
|
148
|
+
content: new File(param.fileName),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
name: param.name,
|
|
153
|
+
content: param.value,
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
const header = getHeaderName(params.headers, 'content-type');
|
|
157
|
+
if (header) {
|
|
158
|
+
delete params.headers[header];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
136
162
|
}
|
|
137
|
-
return {
|
|
138
|
-
name: param.name,
|
|
139
|
-
content: param.value
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
const header = getHeaderName(params.headers, "content-type");
|
|
143
|
-
if (header) {
|
|
144
|
-
delete params.headers[header];
|
|
145
|
-
}
|
|
146
163
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
164
|
+
switch (getHeader(params.headers, 'accept')) {
|
|
165
|
+
case 'application/json':
|
|
166
|
+
{
|
|
167
|
+
params.accept = new Keyword('json');
|
|
168
|
+
const header = getHeaderName(params.headers, 'accept');
|
|
169
|
+
if (header) {
|
|
170
|
+
delete params.headers[header];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
158
174
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
export {
|
|
173
|
-
clj_http
|
|
175
|
+
push("(require '[clj-http.client :as client])\n");
|
|
176
|
+
if (objEmpty(filterEmpty(params))) {
|
|
177
|
+
push(`(client/${method} "${url}")`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const padding = 11 + method.length + url.length;
|
|
181
|
+
const formattedParams = padBlock(padding, jsToEdn(filterEmpty(params)));
|
|
182
|
+
push(`(client/${method} "${url}" ${formattedParams})`);
|
|
183
|
+
}
|
|
184
|
+
return join();
|
|
185
|
+
},
|
|
174
186
|
};
|
|
175
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
import { CodeBuilder } from
|
|
2
|
-
import { escapeForDoubleQuotes } from
|
|
3
|
-
import { getHeader } from
|
|
4
|
-
const restsharp = {
|
|
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
|
-
|
|
1
|
+
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
2
|
+
import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
|
|
3
|
+
import { getHeader } from '../../../../httpsnippet-lite/helpers/headers.js';
|
|
4
|
+
export const restsharp = {
|
|
5
|
+
info: {
|
|
6
|
+
key: 'restsharp',
|
|
7
|
+
title: 'RestSharp',
|
|
8
|
+
link: 'http://restsharp.org/',
|
|
9
|
+
description: 'Simple REST and HTTP API Client for .NET',
|
|
10
|
+
},
|
|
11
|
+
convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }) => {
|
|
12
|
+
const { push, join } = new CodeBuilder();
|
|
13
|
+
const isSupportedMethod = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'].includes(method.toUpperCase());
|
|
14
|
+
if (!isSupportedMethod) {
|
|
15
|
+
return 'Method not supported';
|
|
16
|
+
}
|
|
17
|
+
push(`var client = new RestClient("${fullUrl}");`);
|
|
18
|
+
push(`var request = new RestRequest(Method.${method.toUpperCase()});`);
|
|
19
|
+
// Add headers, including the cookies
|
|
20
|
+
Object.keys(headersObj).forEach((key) => {
|
|
21
|
+
push(`request.AddHeader("${key}", "${escapeForDoubleQuotes(headersObj[key])}");`);
|
|
22
|
+
});
|
|
23
|
+
cookies === null || cookies === void 0
|
|
24
|
+
? void 0
|
|
25
|
+
: cookies.forEach(({ name, value }) => {
|
|
26
|
+
push(`request.AddCookie("${name}", "${value}");`);
|
|
27
|
+
});
|
|
28
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
29
|
+
const header = getHeader(allHeaders, 'content-type');
|
|
30
|
+
const text = JSON.stringify(postData.text);
|
|
31
|
+
push(`request.AddParameter("${header}", ${text}, ParameterType.RequestBody);`);
|
|
32
|
+
}
|
|
33
|
+
push('IRestResponse response = client.Execute(request);');
|
|
34
|
+
return join();
|
|
35
|
+
},
|
|
35
36
|
};
|
|
36
|
-
export {
|
|
37
|
-
restsharp
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=client.js.map
|