@scalar/snippetz 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/index.d.ts.map +1 -1
- package/dist/clients/index.js +7 -5
- package/dist/libs/http.d.ts +29 -0
- package/dist/libs/http.d.ts.map +1 -1
- package/dist/libs/http.js +53 -0
- package/dist/libs/javascript.d.ts.map +1 -1
- package/dist/libs/javascript.js +6 -3
- package/dist/plugins/c/libcurl/libcurl.d.ts.map +1 -1
- package/dist/plugins/c/libcurl/libcurl.js +145 -5
- package/dist/plugins/go/native/native.d.ts.map +1 -1
- package/dist/plugins/go/native/native.js +150 -5
- package/dist/plugins/js/axios/axios.d.ts +1 -2
- package/dist/plugins/js/axios/axios.d.ts.map +1 -1
- package/dist/plugins/js/axios/axios.js +2 -11
- package/dist/plugins/node/axios/axios.d.ts +1 -2
- package/dist/plugins/node/axios/axios.d.ts.map +1 -1
- package/dist/plugins/node/axios/axios.js +2 -11
- package/dist/plugins/php/laravel/index.d.ts +2 -0
- package/dist/plugins/php/laravel/index.d.ts.map +1 -0
- package/dist/plugins/php/laravel/index.js +1 -0
- package/dist/plugins/php/laravel/laravel.d.ts +6 -0
- package/dist/plugins/php/laravel/laravel.d.ts.map +1 -0
- package/dist/plugins/php/laravel/laravel.js +134 -0
- package/dist/plugins/python/aiohttp/aiohttp.d.ts +6 -0
- package/dist/plugins/python/aiohttp/aiohttp.d.ts.map +1 -0
- package/dist/plugins/python/aiohttp/aiohttp.js +107 -0
- package/dist/plugins/python/aiohttp/index.d.ts +2 -0
- package/dist/plugins/python/aiohttp/index.d.ts.map +1 -0
- package/dist/plugins/python/aiohttp/index.js +1 -0
- package/dist/plugins/python/python3/python3.d.ts.map +1 -1
- package/dist/plugins/python/python3/python3.js +192 -5
- package/dist/plugins/python/requestsLike.d.ts +2 -0
- package/dist/plugins/python/requestsLike.d.ts.map +1 -1
- package/dist/plugins/python/requestsLike.js +9 -9
- package/dist/plugins/r/httr2/httr2.d.ts +6 -0
- package/dist/plugins/r/httr2/httr2.d.ts.map +1 -0
- package/dist/plugins/r/httr2/httr2.js +159 -0
- package/dist/plugins/r/httr2/index.d.ts +2 -0
- package/dist/plugins/r/httr2/index.d.ts.map +1 -0
- package/dist/plugins/r/httr2/index.js +1 -0
- package/dist/plugins/ruby/native/native.d.ts.map +1 -1
- package/dist/plugins/ruby/native/native.js +138 -5
- package/dist/plugins/shared/axios.d.ts +3 -0
- package/dist/plugins/shared/axios.d.ts.map +1 -0
- package/dist/plugins/shared/axios.js +148 -0
- package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts.map +1 -1
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +118 -5
- package/dist/snippetz.d.ts +2 -2
- package/package.json +17 -7
- package/dist/httpsnippet-lite/targets/c/libcurl/client.d.ts +0 -3
- package/dist/httpsnippet-lite/targets/c/libcurl/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js +0 -74
- package/dist/httpsnippet-lite/targets/go/native/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/go/native/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/go/native/client.js +0 -157
- package/dist/httpsnippet-lite/targets/javascript/axios/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/javascript/axios/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js +0 -86
- package/dist/httpsnippet-lite/targets/node/axios/client.d.ts +0 -3
- package/dist/httpsnippet-lite/targets/node/axios/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/node/axios/client.js +0 -78
- package/dist/httpsnippet-lite/targets/python/python3/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/python/python3/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/python/python3/client.js +0 -88
- package/dist/httpsnippet-lite/targets/r/httr/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/r/httr/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/r/httr/client.js +0 -115
- package/dist/httpsnippet-lite/targets/ruby/native/client.d.ts +0 -3
- package/dist/httpsnippet-lite/targets/ruby/native/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/ruby/native/client.js +0 -67
- package/dist/httpsnippet-lite/targets/swift/helpers.d.ts +0 -15
- package/dist/httpsnippet-lite/targets/swift/helpers.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/swift/helpers.js +0 -70
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.d.ts +0 -12
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.d.ts.map +0 -1
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +0 -128
- package/dist/plugins/r/httr/httr.d.ts +0 -6
- package/dist/plugins/r/httr/httr.d.ts.map +0 -1
- package/dist/plugins/r/httr/httr.js +0 -14
- package/dist/plugins/r/httr/index.d.ts +0 -2
- package/dist/plugins/r/httr/index.d.ts.map +0 -1
- package/dist/plugins/r/httr/index.js +0 -1
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/scalar/scalar.git",
|
|
10
10
|
"directory": "packages/snippetz"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.9.1",
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=22"
|
|
15
15
|
},
|
|
@@ -157,6 +157,11 @@
|
|
|
157
157
|
"types": "./dist/plugins/php/guzzle/index.d.ts",
|
|
158
158
|
"default": "./dist/plugins/php/guzzle/index.js"
|
|
159
159
|
},
|
|
160
|
+
"./plugins/php/laravel": {
|
|
161
|
+
"import": "./dist/plugins/php/laravel/index.js",
|
|
162
|
+
"types": "./dist/plugins/php/laravel/index.d.ts",
|
|
163
|
+
"default": "./dist/plugins/php/laravel/index.js"
|
|
164
|
+
},
|
|
160
165
|
"./plugins/powershell/restmethod": {
|
|
161
166
|
"import": "./dist/plugins/powershell/restmethod/index.js",
|
|
162
167
|
"types": "./dist/plugins/powershell/restmethod/index.d.ts",
|
|
@@ -167,6 +172,11 @@
|
|
|
167
172
|
"types": "./dist/plugins/powershell/webrequest/index.d.ts",
|
|
168
173
|
"default": "./dist/plugins/powershell/webrequest/index.js"
|
|
169
174
|
},
|
|
175
|
+
"./plugins/python/aiohttp": {
|
|
176
|
+
"import": "./dist/plugins/python/aiohttp/index.js",
|
|
177
|
+
"types": "./dist/plugins/python/aiohttp/index.d.ts",
|
|
178
|
+
"default": "./dist/plugins/python/aiohttp/index.js"
|
|
179
|
+
},
|
|
170
180
|
"./plugins/python/httpx": {
|
|
171
181
|
"import": "./dist/plugins/python/httpx/index.js",
|
|
172
182
|
"types": "./dist/plugins/python/httpx/index.d.ts",
|
|
@@ -182,10 +192,10 @@
|
|
|
182
192
|
"types": "./dist/plugins/python/requests/index.d.ts",
|
|
183
193
|
"default": "./dist/plugins/python/requests/index.js"
|
|
184
194
|
},
|
|
185
|
-
"./plugins/r/
|
|
186
|
-
"import": "./dist/plugins/r/
|
|
187
|
-
"types": "./dist/plugins/r/
|
|
188
|
-
"default": "./dist/plugins/r/
|
|
195
|
+
"./plugins/r/httr2": {
|
|
196
|
+
"import": "./dist/plugins/r/httr2/index.js",
|
|
197
|
+
"types": "./dist/plugins/r/httr2/index.d.ts",
|
|
198
|
+
"default": "./dist/plugins/r/httr2/index.js"
|
|
189
199
|
},
|
|
190
200
|
"./plugins/ruby/native": {
|
|
191
201
|
"import": "./dist/plugins/ruby/native/index.js",
|
|
@@ -230,7 +240,7 @@
|
|
|
230
240
|
"dependencies": {
|
|
231
241
|
"js-base64": "^3.7.8",
|
|
232
242
|
"stringify-object": "^6.0.0",
|
|
233
|
-
"@scalar/types": "0.
|
|
243
|
+
"@scalar/types": "0.9.1"
|
|
234
244
|
},
|
|
235
245
|
"devDependencies": {
|
|
236
246
|
"@types/stringify-object": "^4.0.5",
|
|
@@ -242,7 +252,7 @@
|
|
|
242
252
|
"generate:java-enums": "tsx scripts/generate-java-enums.ts",
|
|
243
253
|
"generate:markdown-docs": "tsx scripts/generate-markdown-docs.ts",
|
|
244
254
|
"postbuild": "pnpm generate:dotnet-enums && pnpm generate:java-enums && pnpm generate:markdown-docs",
|
|
245
|
-
"test": "vitest",
|
|
255
|
+
"test": "vitest --run",
|
|
246
256
|
"types:check": "tsc --noEmit"
|
|
247
257
|
}
|
|
248
258
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/c/libcurl/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,OAAO,EAAE,MAqErB,CAAA"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
2
|
-
import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
|
|
3
|
-
export const libcurl = {
|
|
4
|
-
info: {
|
|
5
|
-
key: 'libcurl',
|
|
6
|
-
title: 'Libcurl',
|
|
7
|
-
link: 'http://curl.haxx.se/libcurl',
|
|
8
|
-
description: 'Simple REST and HTTP API Client for C',
|
|
9
|
-
},
|
|
10
|
-
convert: ({ method, fullUrl, headersObj, allHeaders, postData }) => {
|
|
11
|
-
const { push, blank, join } = new CodeBuilder({ indent: ' ' });
|
|
12
|
-
push('CURL *hnd = curl_easy_init();');
|
|
13
|
-
blank();
|
|
14
|
-
push(`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method.toUpperCase()}");`);
|
|
15
|
-
push(`curl_easy_setopt(hnd, CURLOPT_URL, "${fullUrl}");`);
|
|
16
|
-
// Add headers, including the cookies
|
|
17
|
-
const headers = Object.keys(headersObj);
|
|
18
|
-
// construct headers
|
|
19
|
-
if (headers.length) {
|
|
20
|
-
blank();
|
|
21
|
-
push('struct curl_slist *headers = NULL;');
|
|
22
|
-
headers.forEach((header) => {
|
|
23
|
-
// See https://curl.se/libcurl/c/httpcustomheader.html for syntax
|
|
24
|
-
if (headersObj[header]) {
|
|
25
|
-
push(`headers = curl_slist_append(headers, "${header}: ${escapeForDoubleQuotes(headersObj[header])}");`);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
push(`headers = curl_slist_append(headers, "${header};");`);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);');
|
|
32
|
-
}
|
|
33
|
-
// construct cookies
|
|
34
|
-
if (allHeaders.cookie) {
|
|
35
|
-
blank();
|
|
36
|
-
push(`curl_easy_setopt(hnd, CURLOPT_COOKIE, "${allHeaders.cookie}");`);
|
|
37
|
-
}
|
|
38
|
-
if (postData !== null && postData !== void 0) {
|
|
39
|
-
blank();
|
|
40
|
-
if (postData.text) {
|
|
41
|
-
push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${JSON.stringify(postData.text)});`);
|
|
42
|
-
}
|
|
43
|
-
else if (postData.mimeType === 'application/x-www-form-urlencoded' && postData.params) {
|
|
44
|
-
const formBody = postData.params
|
|
45
|
-
.map((param) => new URLSearchParams([[param.name, param.value ?? '']]).toString())
|
|
46
|
-
.join('&');
|
|
47
|
-
push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "${formBody}");`);
|
|
48
|
-
}
|
|
49
|
-
else if (postData.mimeType === 'multipart/form-data' && postData.params) {
|
|
50
|
-
push('curl_mime *mime = curl_mime_init(hnd);');
|
|
51
|
-
postData.params.forEach((param) => {
|
|
52
|
-
blank();
|
|
53
|
-
push('{');
|
|
54
|
-
push('curl_mimepart *part = curl_mime_addpart(mime);', 1);
|
|
55
|
-
if (param.name) {
|
|
56
|
-
push(`curl_mime_name(part, "${param.name}");`, 1);
|
|
57
|
-
}
|
|
58
|
-
if (param.fileName) {
|
|
59
|
-
push(`curl_mime_filedata(part, "${param.fileName}");`, 1);
|
|
60
|
-
}
|
|
61
|
-
else if (param.value) {
|
|
62
|
-
push(`curl_mime_data(part, "${escapeForDoubleQuotes(param.value)}", CURL_ZERO_TERMINATED);`, 1);
|
|
63
|
-
}
|
|
64
|
-
push('}');
|
|
65
|
-
});
|
|
66
|
-
blank();
|
|
67
|
-
push('curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime);');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
blank();
|
|
71
|
-
push('CURLcode ret = curl_easy_perform(hnd);');
|
|
72
|
-
return join();
|
|
73
|
-
},
|
|
74
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
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 type { Client } from '../../../../httpsnippet-lite/targets/target.js';
|
|
11
|
-
export declare const native: Client;
|
|
12
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/go/native/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,MAAM,EAAE,MA+JpB,CAAA"}
|
|
@@ -1,157 +0,0 @@
|
|
|
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);
|
|
71
|
-
blank();
|
|
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
|
-
});
|
|
131
|
-
blank();
|
|
132
|
-
}
|
|
133
|
-
// Make request
|
|
134
|
-
push(`res, ${errorPlaceholder} := ${client}.Do(req)`, indent);
|
|
135
|
-
errorCheck();
|
|
136
|
-
// Get Body
|
|
137
|
-
if (printBody) {
|
|
138
|
-
imports.add('io');
|
|
139
|
-
blank();
|
|
140
|
-
push('defer res.Body.Close()', indent);
|
|
141
|
-
push(`body, ${errorPlaceholder} := io.ReadAll(res.Body)`, indent);
|
|
142
|
-
errorCheck();
|
|
143
|
-
}
|
|
144
|
-
// Print it
|
|
145
|
-
blank();
|
|
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
|
-
},
|
|
157
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
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 type { Client } from '../../../../httpsnippet-lite/targets/target.js';
|
|
11
|
-
export declare const axios: Client;
|
|
12
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/javascript/axios/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,KAAK,EAAE,MAgFnB,CAAA"}
|
|
@@ -1,86 +0,0 @@
|
|
|
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;
|
|
35
|
-
}
|
|
36
|
-
if (Object.keys(allHeaders).length) {
|
|
37
|
-
requestOptions.headers = allHeaders;
|
|
38
|
-
}
|
|
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
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const optionString = stringifyObject(requestOptions, {
|
|
73
|
-
indent: ' ',
|
|
74
|
-
inlineCharacterLimit: 80,
|
|
75
|
-
}).replace('"[form]"', 'form');
|
|
76
|
-
push(`const options = ${optionString};`);
|
|
77
|
-
blank();
|
|
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
|
-
},
|
|
86
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/node/axios/client.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,KAAK,EAAE,MAwEnB,CAAA"}
|
|
@@ -1,78 +0,0 @@
|
|
|
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: ({ method, url, queryObj, allHeaders, postData }, options) => {
|
|
20
|
-
const opts = {
|
|
21
|
-
indent: ' ',
|
|
22
|
-
...options,
|
|
23
|
-
};
|
|
24
|
-
const { blank, join, push, addPostProcessor } = new CodeBuilder({
|
|
25
|
-
indent: opts.indent,
|
|
26
|
-
});
|
|
27
|
-
push("const axios = require('axios').default;");
|
|
28
|
-
const reqOpts = {
|
|
29
|
-
method,
|
|
30
|
-
url,
|
|
31
|
-
};
|
|
32
|
-
if (Object.keys(queryObj).length) {
|
|
33
|
-
reqOpts.params = queryObj;
|
|
34
|
-
}
|
|
35
|
-
if (Object.keys(allHeaders).length) {
|
|
36
|
-
reqOpts.headers = allHeaders;
|
|
37
|
-
}
|
|
38
|
-
switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
|
|
39
|
-
case 'application/x-www-form-urlencoded':
|
|
40
|
-
if (postData.params) {
|
|
41
|
-
push("const { URLSearchParams } = require('url');");
|
|
42
|
-
blank();
|
|
43
|
-
push('const encodedParams = new URLSearchParams();');
|
|
44
|
-
postData.params.forEach((param) => {
|
|
45
|
-
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
46
|
-
});
|
|
47
|
-
blank();
|
|
48
|
-
reqOpts.data = 'encodedParams,';
|
|
49
|
-
addPostProcessor((code) => code.replace(/'encodedParams,'/, 'encodedParams,'));
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
case 'application/json':
|
|
53
|
-
blank();
|
|
54
|
-
if (postData?.jsonObj) {
|
|
55
|
-
reqOpts.data = postData.jsonObj;
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
default:
|
|
59
|
-
blank();
|
|
60
|
-
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
61
|
-
reqOpts.data = postData.text;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const stringifiedOptions = stringifyObject(reqOpts, {
|
|
65
|
-
indent: ' ',
|
|
66
|
-
inlineCharacterLimit: 80,
|
|
67
|
-
});
|
|
68
|
-
push(`const options = ${stringifiedOptions};`);
|
|
69
|
-
blank();
|
|
70
|
-
push('try {');
|
|
71
|
-
push('const { data } = await axios.request(options);', 1);
|
|
72
|
-
push('console.log(data);', 1);
|
|
73
|
-
push('} catch (error) {');
|
|
74
|
-
push('console.error(error);', 1);
|
|
75
|
-
push('}');
|
|
76
|
-
return join();
|
|
77
|
-
},
|
|
78
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for native Python3.
|
|
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 type { Client } from '../../../../httpsnippet-lite/targets/target.js';
|
|
11
|
-
export declare const python3: Client;
|
|
12
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/python/python3/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,OAAO,EAAE,MAsErB,CAAA"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for native Python3.
|
|
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 python3 = {
|
|
13
|
-
info: {
|
|
14
|
-
key: 'python3',
|
|
15
|
-
title: 'http.client',
|
|
16
|
-
link: 'https://docs.python.org/3/library/http.client.html',
|
|
17
|
-
description: 'Python3 HTTP Client',
|
|
18
|
-
},
|
|
19
|
-
convert: ({ uriObj: { path, protocol, host }, postData, allHeaders, method }, options = {}) => {
|
|
20
|
-
const { insecureSkipVerify = false } = options;
|
|
21
|
-
const { push, blank, join } = new CodeBuilder();
|
|
22
|
-
// Start Request
|
|
23
|
-
push('import http.client');
|
|
24
|
-
if (insecureSkipVerify) {
|
|
25
|
-
push('import ssl');
|
|
26
|
-
}
|
|
27
|
-
blank();
|
|
28
|
-
// Check which protocol to be used for the client connection
|
|
29
|
-
if (protocol === 'https:') {
|
|
30
|
-
const sslContext = insecureSkipVerify ? ', context = ssl._create_unverified_context()' : '';
|
|
31
|
-
push(`conn = http.client.HTTPSConnection("${host}"${sslContext})`);
|
|
32
|
-
blank();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
push(`conn = http.client.HTTPConnection("${host}")`);
|
|
36
|
-
blank();
|
|
37
|
-
}
|
|
38
|
-
// Create payload string if it exists
|
|
39
|
-
const payload = JSON.stringify(postData === null || postData === void 0 ? void 0 : postData.text);
|
|
40
|
-
if (payload) {
|
|
41
|
-
push(`payload = ${payload}`);
|
|
42
|
-
blank();
|
|
43
|
-
}
|
|
44
|
-
// Create Headers
|
|
45
|
-
const headers = allHeaders;
|
|
46
|
-
const headerCount = Object.keys(headers).length;
|
|
47
|
-
if (headerCount === 1) {
|
|
48
|
-
for (const header in headers) {
|
|
49
|
-
push(`headers = { '${header}': "${escapeForDoubleQuotes(headers[header])}" }`);
|
|
50
|
-
blank();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (headerCount > 1) {
|
|
54
|
-
let count = 1;
|
|
55
|
-
push('headers = {');
|
|
56
|
-
for (const header in headers) {
|
|
57
|
-
if (count++ !== headerCount) {
|
|
58
|
-
push(` '${header}': "${escapeForDoubleQuotes(headers[header])}",`);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
push(` '${header}': "${escapeForDoubleQuotes(headers[header])}"`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
push('}');
|
|
65
|
-
blank();
|
|
66
|
-
}
|
|
67
|
-
// Make Request
|
|
68
|
-
if (payload && headerCount) {
|
|
69
|
-
push(`conn.request("${method}", "${path}", payload, headers)`);
|
|
70
|
-
}
|
|
71
|
-
else if (payload && !headerCount) {
|
|
72
|
-
push(`conn.request("${method}", "${path}", payload)`);
|
|
73
|
-
}
|
|
74
|
-
else if (!payload && headerCount) {
|
|
75
|
-
push(`conn.request("${method}", "${path}", headers=headers)`);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
push(`conn.request("${method}", "${path}")`);
|
|
79
|
-
}
|
|
80
|
-
// Get Response
|
|
81
|
-
blank();
|
|
82
|
-
push('res = conn.getresponse()');
|
|
83
|
-
push('data = res.read()');
|
|
84
|
-
blank();
|
|
85
|
-
push('print(data.decode("utf-8"))');
|
|
86
|
-
return join();
|
|
87
|
-
},
|
|
88
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for R using httr
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @gabrielakoreeda
|
|
7
|
-
*
|
|
8
|
-
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
-
*/
|
|
10
|
-
import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
|
|
11
|
-
export declare const httr: Client;
|
|
12
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/r/httr/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,IAAI,EAAE,MAuGlB,CAAA"}
|