@readme/httpsnippet 10.1.1 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{chunk-Y7NI4MMY.js → chunk-6B3J3CUI.js} +2 -2
- package/dist/chunk-6B3J3CUI.js.map +1 -0
- package/dist/{chunk-532RKFLR.js → chunk-EFUQ6POB.js} +77 -276
- package/dist/chunk-EFUQ6POB.js.map +1 -0
- package/dist/{chunk-KT7MO6Z4.js → chunk-LCVMSGCB.js} +2 -2
- package/dist/chunk-LCVMSGCB.js.map +1 -0
- package/dist/helpers/code-builder.cjs.map +1 -1
- package/dist/helpers/code-builder.js +1 -1
- package/dist/helpers/reducer.cjs.map +1 -1
- package/dist/helpers/reducer.js +1 -1
- package/dist/index.cjs +141 -325
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +27 -12
- package/dist/index.js.map +1 -1
- package/dist/targets/index.cjs +75 -274
- package/dist/targets/index.cjs.map +1 -1
- package/dist/targets/index.d.cts +160 -6
- package/dist/targets/index.d.ts +160 -6
- package/dist/targets/index.js +2 -2
- package/package.json +16 -17
- package/dist/chunk-532RKFLR.js.map +0 -1
- package/dist/chunk-KT7MO6Z4.js.map +0 -1
- package/dist/chunk-Y7NI4MMY.js.map +0 -1
- package/dist/index-Bi-oJSCB.d.ts +0 -164
- package/dist/index-CM3ebXTM.d.cts +0 -164
package/dist/targets/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var stringifyObject7 = require('stringify-object');
|
|
4
4
|
|
|
5
5
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var stringifyObject7__default = /*#__PURE__*/_interopDefault(stringifyObject7);
|
|
8
8
|
|
|
9
9
|
// src/helpers/code-builder.ts
|
|
10
10
|
var DEFAULT_INDENTATION_CHARACTER = "";
|
|
@@ -497,7 +497,7 @@ var restsharp = {
|
|
|
497
497
|
link: "http://restsharp.org/",
|
|
498
498
|
description: "Simple REST and HTTP API Client for .NET",
|
|
499
499
|
extname: ".cs",
|
|
500
|
-
installation: "dotnet add package RestSharp"
|
|
500
|
+
installation: () => "dotnet add package RestSharp"
|
|
501
501
|
},
|
|
502
502
|
convert: ({ method, fullUrl, headersObj, cookies, postData, uriObj }) => {
|
|
503
503
|
const { push, join } = new CodeBuilder();
|
|
@@ -906,7 +906,7 @@ var axios = {
|
|
|
906
906
|
link: "https://github.com/axios/axios",
|
|
907
907
|
description: "Promise based HTTP client for the browser and node.js",
|
|
908
908
|
extname: ".js",
|
|
909
|
-
installation: "npm install axios --save"
|
|
909
|
+
installation: () => "npm install axios --save"
|
|
910
910
|
},
|
|
911
911
|
convert: ({ allHeaders, method, url, queryObj, postData }, options) => {
|
|
912
912
|
const opts = {
|
|
@@ -959,7 +959,7 @@ var axios = {
|
|
|
959
959
|
requestOptions.data = postData.text;
|
|
960
960
|
}
|
|
961
961
|
}
|
|
962
|
-
const optionString =
|
|
962
|
+
const optionString = stringifyObject7__default.default(requestOptions, {
|
|
963
963
|
indent: " ",
|
|
964
964
|
inlineCharacterLimit: 80
|
|
965
965
|
}).replace('"[form]"', "form");
|
|
@@ -967,12 +967,8 @@ var axios = {
|
|
|
967
967
|
blank();
|
|
968
968
|
push("axios");
|
|
969
969
|
push(".request(options)", 1);
|
|
970
|
-
push(".then(
|
|
971
|
-
push("console.
|
|
972
|
-
push("})", 1);
|
|
973
|
-
push(".catch(function (error) {", 1);
|
|
974
|
-
push("console.error(error);", 2);
|
|
975
|
-
push("});", 1);
|
|
970
|
+
push(".then(res => console.log(res.data))", 1);
|
|
971
|
+
push(".catch(err => console.error(err));", 1);
|
|
976
972
|
return join();
|
|
977
973
|
}
|
|
978
974
|
};
|
|
@@ -1009,7 +1005,7 @@ var fetch = {
|
|
|
1009
1005
|
options.body = postData.jsonObj;
|
|
1010
1006
|
}
|
|
1011
1007
|
break;
|
|
1012
|
-
case "multipart/form-data":
|
|
1008
|
+
case "multipart/form-data": {
|
|
1013
1009
|
if (!postData.params) {
|
|
1014
1010
|
break;
|
|
1015
1011
|
}
|
|
@@ -1023,6 +1019,7 @@ var fetch = {
|
|
|
1023
1019
|
});
|
|
1024
1020
|
blank();
|
|
1025
1021
|
break;
|
|
1022
|
+
}
|
|
1026
1023
|
default:
|
|
1027
1024
|
if (postData.text) {
|
|
1028
1025
|
options.body = postData.text;
|
|
@@ -1032,7 +1029,7 @@ var fetch = {
|
|
|
1032
1029
|
delete options.headers;
|
|
1033
1030
|
}
|
|
1034
1031
|
push(
|
|
1035
|
-
`const options = ${
|
|
1032
|
+
`const options = ${stringifyObject7__default.default(options, {
|
|
1036
1033
|
indent: opts.indent,
|
|
1037
1034
|
inlineCharacterLimit: 80,
|
|
1038
1035
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult
|
|
@@ -1056,8 +1053,8 @@ var fetch = {
|
|
|
1056
1053
|
blank();
|
|
1057
1054
|
}
|
|
1058
1055
|
push(`fetch('${fullUrl}', options)`);
|
|
1059
|
-
push(".then(
|
|
1060
|
-
push(".then(
|
|
1056
|
+
push(".then(res => res.json())", 1);
|
|
1057
|
+
push(".then(res => console.log(res))", 1);
|
|
1061
1058
|
push(".catch(err => console.error(err));", 1);
|
|
1062
1059
|
return join();
|
|
1063
1060
|
}
|
|
@@ -1118,11 +1115,11 @@ var jquery = {
|
|
|
1118
1115
|
settings.data = postData.text;
|
|
1119
1116
|
}
|
|
1120
1117
|
}
|
|
1121
|
-
const stringifiedSettings =
|
|
1118
|
+
const stringifiedSettings = stringifyObject7__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
|
|
1122
1119
|
push(`const settings = ${stringifiedSettings};`);
|
|
1123
1120
|
blank();
|
|
1124
|
-
push("$.ajax(settings).done(
|
|
1125
|
-
push("console.log(
|
|
1121
|
+
push("$.ajax(settings).done(res => {");
|
|
1122
|
+
push("console.log(res);", 1);
|
|
1126
1123
|
push("});");
|
|
1127
1124
|
return join();
|
|
1128
1125
|
}
|
|
@@ -1145,7 +1142,7 @@ var xhr = {
|
|
|
1145
1142
|
switch (postData.mimeType) {
|
|
1146
1143
|
case "application/json":
|
|
1147
1144
|
push(
|
|
1148
|
-
`const data = JSON.stringify(${
|
|
1145
|
+
`const data = JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
|
|
1149
1146
|
indent: opts.indent
|
|
1150
1147
|
})});`
|
|
1151
1148
|
);
|
|
@@ -1199,7 +1196,7 @@ var javascript = {
|
|
|
1199
1196
|
info: {
|
|
1200
1197
|
key: "javascript",
|
|
1201
1198
|
title: "JavaScript",
|
|
1202
|
-
default: "
|
|
1199
|
+
default: "fetch"
|
|
1203
1200
|
},
|
|
1204
1201
|
clientsById: {
|
|
1205
1202
|
xhr,
|
|
@@ -1233,7 +1230,7 @@ var native2 = {
|
|
|
1233
1230
|
payload = postData.jsonObj;
|
|
1234
1231
|
}
|
|
1235
1232
|
break;
|
|
1236
|
-
case "multipart/form-data":
|
|
1233
|
+
case "multipart/form-data": {
|
|
1237
1234
|
if (!postData.params) {
|
|
1238
1235
|
break;
|
|
1239
1236
|
}
|
|
@@ -1243,6 +1240,7 @@ var native2 = {
|
|
|
1243
1240
|
});
|
|
1244
1241
|
payload = multipartPayload;
|
|
1245
1242
|
break;
|
|
1243
|
+
}
|
|
1246
1244
|
default:
|
|
1247
1245
|
if (postData.text) {
|
|
1248
1246
|
payload = postData.text;
|
|
@@ -1338,8 +1336,8 @@ var axios2 = {
|
|
|
1338
1336
|
title: "Axios",
|
|
1339
1337
|
link: "https://github.com/axios/axios",
|
|
1340
1338
|
description: "Promise based HTTP client for the browser and node.js",
|
|
1341
|
-
extname: ".
|
|
1342
|
-
installation: "npm install axios --save"
|
|
1339
|
+
extname: ".js",
|
|
1340
|
+
installation: () => "npm install axios --save"
|
|
1343
1341
|
},
|
|
1344
1342
|
convert: ({ method, fullUrl, allHeaders, postData }, options) => {
|
|
1345
1343
|
const opts = {
|
|
@@ -1347,7 +1345,8 @@ var axios2 = {
|
|
|
1347
1345
|
...options
|
|
1348
1346
|
};
|
|
1349
1347
|
const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1350
|
-
push("
|
|
1348
|
+
push("import axios from 'axios';");
|
|
1349
|
+
blank();
|
|
1351
1350
|
const reqOpts = {
|
|
1352
1351
|
method,
|
|
1353
1352
|
url: fullUrl
|
|
@@ -1358,8 +1357,6 @@ var axios2 = {
|
|
|
1358
1357
|
switch (postData.mimeType) {
|
|
1359
1358
|
case "application/x-www-form-urlencoded":
|
|
1360
1359
|
if (postData.params) {
|
|
1361
|
-
push("const { URLSearchParams } = require('url');");
|
|
1362
|
-
blank();
|
|
1363
1360
|
push("const encodedParams = new URLSearchParams();");
|
|
1364
1361
|
postData.params.forEach((param) => {
|
|
1365
1362
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
@@ -1370,39 +1367,32 @@ var axios2 = {
|
|
|
1370
1367
|
}
|
|
1371
1368
|
break;
|
|
1372
1369
|
case "application/json":
|
|
1373
|
-
blank();
|
|
1374
1370
|
if (postData.jsonObj) {
|
|
1375
1371
|
reqOpts.data = postData.jsonObj;
|
|
1376
1372
|
}
|
|
1377
1373
|
break;
|
|
1378
1374
|
default:
|
|
1379
|
-
blank();
|
|
1380
1375
|
if (postData.text) {
|
|
1381
1376
|
reqOpts.data = postData.text;
|
|
1382
1377
|
}
|
|
1383
1378
|
}
|
|
1384
|
-
const stringifiedOptions =
|
|
1379
|
+
const stringifiedOptions = stringifyObject7__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
|
|
1385
1380
|
push(`const options = ${stringifiedOptions};`);
|
|
1386
1381
|
blank();
|
|
1387
1382
|
push("axios");
|
|
1388
1383
|
push(".request(options)", 1);
|
|
1389
|
-
push(".then(
|
|
1390
|
-
push("console.
|
|
1391
|
-
push("})", 1);
|
|
1392
|
-
push(".catch(function (error) {", 1);
|
|
1393
|
-
push("console.error(error);", 2);
|
|
1394
|
-
push("});", 1);
|
|
1384
|
+
push(".then(res => console.log(res.data))", 1);
|
|
1385
|
+
push(".catch(err => console.error(err));", 1);
|
|
1395
1386
|
return join();
|
|
1396
1387
|
}
|
|
1397
1388
|
};
|
|
1398
1389
|
var fetch2 = {
|
|
1399
1390
|
info: {
|
|
1400
1391
|
key: "fetch",
|
|
1401
|
-
title: "
|
|
1402
|
-
link: "https://
|
|
1403
|
-
description: "
|
|
1404
|
-
extname: ".
|
|
1405
|
-
installation: "npm install node-fetch@2 --save"
|
|
1392
|
+
title: "fetch",
|
|
1393
|
+
link: "https://nodejs.org/docs/latest/api/globals.html#fetch",
|
|
1394
|
+
description: "Perform asynchronous HTTP requests with the Fetch API",
|
|
1395
|
+
extname: ".js"
|
|
1406
1396
|
},
|
|
1407
1397
|
convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1408
1398
|
const opts = {
|
|
@@ -1411,7 +1401,6 @@ var fetch2 = {
|
|
|
1411
1401
|
};
|
|
1412
1402
|
let includeFS = false;
|
|
1413
1403
|
const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
|
|
1414
|
-
push("const fetch = require('node-fetch');");
|
|
1415
1404
|
const url = fullUrl;
|
|
1416
1405
|
const reqOpts = {
|
|
1417
1406
|
method
|
|
@@ -1421,20 +1410,19 @@ var fetch2 = {
|
|
|
1421
1410
|
}
|
|
1422
1411
|
switch (postData.mimeType) {
|
|
1423
1412
|
case "application/x-www-form-urlencoded":
|
|
1424
|
-
unshift("const { URLSearchParams } = require('url');");
|
|
1425
1413
|
push("const encodedParams = new URLSearchParams();");
|
|
1426
|
-
blank();
|
|
1427
1414
|
postData.params?.forEach((param) => {
|
|
1428
1415
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
1429
1416
|
});
|
|
1430
1417
|
reqOpts.body = "encodedParams";
|
|
1418
|
+
blank();
|
|
1431
1419
|
break;
|
|
1432
1420
|
case "application/json":
|
|
1433
1421
|
if (postData.jsonObj) {
|
|
1434
1422
|
reqOpts.body = postData.jsonObj;
|
|
1435
1423
|
}
|
|
1436
1424
|
break;
|
|
1437
|
-
case "multipart/form-data":
|
|
1425
|
+
case "multipart/form-data": {
|
|
1438
1426
|
if (!postData.params) {
|
|
1439
1427
|
break;
|
|
1440
1428
|
}
|
|
@@ -1442,9 +1430,7 @@ var fetch2 = {
|
|
|
1442
1430
|
if (contentTypeHeader) {
|
|
1443
1431
|
delete headersObj[contentTypeHeader];
|
|
1444
1432
|
}
|
|
1445
|
-
unshift("const FormData = require('form-data');");
|
|
1446
1433
|
push("const formData = new FormData();");
|
|
1447
|
-
blank();
|
|
1448
1434
|
postData.params.forEach((param) => {
|
|
1449
1435
|
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1450
1436
|
push(`formData.append('${param.name}', '${param.value}');`);
|
|
@@ -1452,10 +1438,15 @@ var fetch2 = {
|
|
|
1452
1438
|
}
|
|
1453
1439
|
if (param.fileName) {
|
|
1454
1440
|
includeFS = true;
|
|
1455
|
-
push(
|
|
1441
|
+
push(
|
|
1442
|
+
`formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`
|
|
1443
|
+
);
|
|
1456
1444
|
}
|
|
1457
1445
|
});
|
|
1446
|
+
reqOpts.body = "formData";
|
|
1447
|
+
blank();
|
|
1458
1448
|
break;
|
|
1449
|
+
}
|
|
1459
1450
|
default:
|
|
1460
1451
|
if (postData.text) {
|
|
1461
1452
|
reqOpts.body = postData.text;
|
|
@@ -1470,12 +1461,11 @@ var fetch2 = {
|
|
|
1470
1461
|
reqOpts.headers.cookie = cookiesString;
|
|
1471
1462
|
}
|
|
1472
1463
|
}
|
|
1473
|
-
blank();
|
|
1474
1464
|
push(`const url = '${url}';`);
|
|
1475
1465
|
if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
|
|
1476
1466
|
delete reqOpts.headers;
|
|
1477
1467
|
}
|
|
1478
|
-
const stringifiedOptions =
|
|
1468
|
+
const stringifiedOptions = stringifyObject7__default.default(reqOpts, {
|
|
1479
1469
|
indent: " ",
|
|
1480
1470
|
inlineCharacterLimit: 80,
|
|
1481
1471
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
|
|
@@ -1491,17 +1481,13 @@ var fetch2 = {
|
|
|
1491
1481
|
push(`const options = ${stringifiedOptions};`);
|
|
1492
1482
|
blank();
|
|
1493
1483
|
if (includeFS) {
|
|
1494
|
-
unshift("
|
|
1495
|
-
}
|
|
1496
|
-
if (postData.params && postData.mimeType === "multipart/form-data") {
|
|
1497
|
-
push("options.body = formData;");
|
|
1498
|
-
blank();
|
|
1484
|
+
unshift("import fs from 'fs';\n");
|
|
1499
1485
|
}
|
|
1500
1486
|
push("fetch(url, options)");
|
|
1501
1487
|
push(".then(res => res.json())", 1);
|
|
1502
1488
|
push(".then(json => console.log(json))", 1);
|
|
1503
|
-
push(".catch(err => console.error(
|
|
1504
|
-
return join().replace(/'encodedParams'/, "encodedParams").replace(/
|
|
1489
|
+
push(".catch(err => console.error(err));", 1);
|
|
1490
|
+
return join().replace(/'encodedParams'/, "encodedParams").replace(/'formData'/, "formData");
|
|
1505
1491
|
}
|
|
1506
1492
|
};
|
|
1507
1493
|
var native3 = {
|
|
@@ -1524,7 +1510,7 @@ var native3 = {
|
|
|
1524
1510
|
};
|
|
1525
1511
|
push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
|
|
1526
1512
|
blank();
|
|
1527
|
-
push(`const options = ${
|
|
1513
|
+
push(`const options = ${stringifyObject7__default.default(reqOpts, { indent })};`);
|
|
1528
1514
|
blank();
|
|
1529
1515
|
push("const req = http.request(options, function (res) {");
|
|
1530
1516
|
push("const chunks = [];", 1);
|
|
@@ -1544,7 +1530,7 @@ var native3 = {
|
|
|
1544
1530
|
if (postData.paramsObj) {
|
|
1545
1531
|
unshift("const qs = require('querystring');");
|
|
1546
1532
|
push(
|
|
1547
|
-
`req.write(qs.stringify(${
|
|
1533
|
+
`req.write(qs.stringify(${stringifyObject7__default.default(postData.paramsObj, {
|
|
1548
1534
|
indent: " ",
|
|
1549
1535
|
inlineCharacterLimit: 80
|
|
1550
1536
|
})}));`
|
|
@@ -1554,7 +1540,7 @@ var native3 = {
|
|
|
1554
1540
|
case "application/json":
|
|
1555
1541
|
if (postData.jsonObj) {
|
|
1556
1542
|
push(
|
|
1557
|
-
`req.write(JSON.stringify(${
|
|
1543
|
+
`req.write(JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
|
|
1558
1544
|
indent: " ",
|
|
1559
1545
|
inlineCharacterLimit: 80
|
|
1560
1546
|
})}));`
|
|
@@ -1563,208 +1549,24 @@ var native3 = {
|
|
|
1563
1549
|
break;
|
|
1564
1550
|
default:
|
|
1565
1551
|
if (postData.text) {
|
|
1566
|
-
push(`req.write(${
|
|
1552
|
+
push(`req.write(${stringifyObject7__default.default(postData.text, { indent })});`);
|
|
1567
1553
|
}
|
|
1568
1554
|
}
|
|
1569
1555
|
push("req.end();");
|
|
1570
1556
|
return join();
|
|
1571
1557
|
}
|
|
1572
1558
|
};
|
|
1573
|
-
var request = {
|
|
1574
|
-
info: {
|
|
1575
|
-
key: "request",
|
|
1576
|
-
title: "Request",
|
|
1577
|
-
link: "https://github.com/request/request",
|
|
1578
|
-
description: "Simplified HTTP request client",
|
|
1579
|
-
extname: ".cjs",
|
|
1580
|
-
installation: "npm install request --save"
|
|
1581
|
-
},
|
|
1582
|
-
convert: ({ method, url, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1583
|
-
const opts = {
|
|
1584
|
-
indent: " ",
|
|
1585
|
-
...options
|
|
1586
|
-
};
|
|
1587
|
-
let includeFS = false;
|
|
1588
|
-
const { push, blank, join, unshift, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1589
|
-
push("const request = require('request');");
|
|
1590
|
-
blank();
|
|
1591
|
-
const reqOpts = {
|
|
1592
|
-
method,
|
|
1593
|
-
url: fullUrl
|
|
1594
|
-
};
|
|
1595
|
-
if (Object.keys(headersObj).length) {
|
|
1596
|
-
reqOpts.headers = headersObj;
|
|
1597
|
-
}
|
|
1598
|
-
switch (postData.mimeType) {
|
|
1599
|
-
case "application/x-www-form-urlencoded":
|
|
1600
|
-
reqOpts.form = postData.paramsObj;
|
|
1601
|
-
break;
|
|
1602
|
-
case "application/json":
|
|
1603
|
-
if (postData.jsonObj) {
|
|
1604
|
-
reqOpts.body = postData.jsonObj;
|
|
1605
|
-
reqOpts.json = true;
|
|
1606
|
-
}
|
|
1607
|
-
break;
|
|
1608
|
-
case "multipart/form-data":
|
|
1609
|
-
if (!postData.params) {
|
|
1610
|
-
break;
|
|
1611
|
-
}
|
|
1612
|
-
reqOpts.formData = {};
|
|
1613
|
-
postData.params.forEach((param) => {
|
|
1614
|
-
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1615
|
-
reqOpts.formData[param.name] = param.value;
|
|
1616
|
-
return;
|
|
1617
|
-
}
|
|
1618
|
-
let attachment = {};
|
|
1619
|
-
if (param.fileName) {
|
|
1620
|
-
includeFS = true;
|
|
1621
|
-
attachment = {
|
|
1622
|
-
value: `fs.createReadStream(${param.fileName})`,
|
|
1623
|
-
options: {
|
|
1624
|
-
filename: param.fileName,
|
|
1625
|
-
contentType: param.contentType ? param.contentType : null
|
|
1626
|
-
}
|
|
1627
|
-
};
|
|
1628
|
-
} else if (param.value) {
|
|
1629
|
-
attachment.value = param.value;
|
|
1630
|
-
}
|
|
1631
|
-
reqOpts.formData[param.name] = attachment;
|
|
1632
|
-
});
|
|
1633
|
-
addPostProcessor((code) => code.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')"));
|
|
1634
|
-
break;
|
|
1635
|
-
default:
|
|
1636
|
-
if (postData.text) {
|
|
1637
|
-
reqOpts.body = postData.text;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
if (cookies.length) {
|
|
1641
|
-
reqOpts.jar = "JAR";
|
|
1642
|
-
push("const jar = request.jar();");
|
|
1643
|
-
cookies.forEach(({ name, value }) => {
|
|
1644
|
-
push(`jar.setCookie(request.cookie('${encodeURIComponent(name)}=${encodeURIComponent(value)}'), '${url}');`);
|
|
1645
|
-
});
|
|
1646
|
-
blank();
|
|
1647
|
-
addPostProcessor((code) => code.replace(/'JAR'/, "jar"));
|
|
1648
|
-
}
|
|
1649
|
-
if (includeFS) {
|
|
1650
|
-
unshift("const fs = require('fs');");
|
|
1651
|
-
}
|
|
1652
|
-
push(`const options = ${stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 })};`);
|
|
1653
|
-
blank();
|
|
1654
|
-
push("request(options, function (error, response, body) {");
|
|
1655
|
-
push("if (error) throw new Error(error);", 1);
|
|
1656
|
-
blank();
|
|
1657
|
-
push("console.log(body);", 1);
|
|
1658
|
-
push("});");
|
|
1659
|
-
return join();
|
|
1660
|
-
}
|
|
1661
|
-
};
|
|
1662
|
-
var unirest2 = {
|
|
1663
|
-
info: {
|
|
1664
|
-
key: "unirest",
|
|
1665
|
-
title: "Unirest",
|
|
1666
|
-
link: "http://unirest.io/nodejs.html",
|
|
1667
|
-
description: "Lightweight HTTP Request Client Library",
|
|
1668
|
-
extname: ".cjs"
|
|
1669
|
-
},
|
|
1670
|
-
convert: ({ method, url, cookies, queryObj, postData, headersObj }, options) => {
|
|
1671
|
-
const opts = {
|
|
1672
|
-
indent: " ",
|
|
1673
|
-
...options
|
|
1674
|
-
};
|
|
1675
|
-
let includeFS = false;
|
|
1676
|
-
const { addPostProcessor, blank, join, push, unshift } = new CodeBuilder({
|
|
1677
|
-
indent: opts.indent
|
|
1678
|
-
});
|
|
1679
|
-
push("const unirest = require('unirest');");
|
|
1680
|
-
blank();
|
|
1681
|
-
push(`const req = unirest('${method}', '${url}');`);
|
|
1682
|
-
blank();
|
|
1683
|
-
if (cookies.length) {
|
|
1684
|
-
push("const CookieJar = unirest.jar();");
|
|
1685
|
-
cookies.forEach((cookie) => {
|
|
1686
|
-
push(`CookieJar.add('${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}', '${url}');`);
|
|
1687
|
-
});
|
|
1688
|
-
push("req.jar(CookieJar);");
|
|
1689
|
-
blank();
|
|
1690
|
-
}
|
|
1691
|
-
if (Object.keys(queryObj).length) {
|
|
1692
|
-
push(`req.query(${stringifyObject9__default.default(queryObj, { indent: opts.indent })});`);
|
|
1693
|
-
blank();
|
|
1694
|
-
}
|
|
1695
|
-
if (Object.keys(headersObj).length) {
|
|
1696
|
-
push(`req.headers(${stringifyObject9__default.default(headersObj, { indent: opts.indent })});`);
|
|
1697
|
-
blank();
|
|
1698
|
-
}
|
|
1699
|
-
switch (postData.mimeType) {
|
|
1700
|
-
case "application/x-www-form-urlencoded":
|
|
1701
|
-
if (postData.paramsObj) {
|
|
1702
|
-
push(`req.form(${stringifyObject9__default.default(postData.paramsObj, { indent: opts.indent })});`);
|
|
1703
|
-
blank();
|
|
1704
|
-
}
|
|
1705
|
-
break;
|
|
1706
|
-
case "application/json":
|
|
1707
|
-
if (postData.jsonObj) {
|
|
1708
|
-
push("req.type('json');");
|
|
1709
|
-
push(`req.send(${stringifyObject9__default.default(postData.jsonObj, { indent: opts.indent })});`);
|
|
1710
|
-
blank();
|
|
1711
|
-
}
|
|
1712
|
-
break;
|
|
1713
|
-
case "multipart/form-data": {
|
|
1714
|
-
if (!postData.params) {
|
|
1715
|
-
break;
|
|
1716
|
-
}
|
|
1717
|
-
const multipart = [];
|
|
1718
|
-
postData.params.forEach((param) => {
|
|
1719
|
-
const part = {};
|
|
1720
|
-
if (param.fileName && !param.value) {
|
|
1721
|
-
includeFS = true;
|
|
1722
|
-
part.body = `fs.createReadStream('${param.fileName}')`;
|
|
1723
|
-
addPostProcessor((code) => code.replace(/'fs\.createReadStream\(\\'(.+)\\'\)'/, "fs.createReadStream('$1')"));
|
|
1724
|
-
} else if (param.value) {
|
|
1725
|
-
part.body = param.value;
|
|
1726
|
-
}
|
|
1727
|
-
if (part.body) {
|
|
1728
|
-
if (param.contentType) {
|
|
1729
|
-
part["content-type"] = param.contentType;
|
|
1730
|
-
}
|
|
1731
|
-
multipart.push(part);
|
|
1732
|
-
}
|
|
1733
|
-
});
|
|
1734
|
-
push(`req.multipart(${stringifyObject9__default.default(multipart, { indent: opts.indent })});`);
|
|
1735
|
-
blank();
|
|
1736
|
-
break;
|
|
1737
|
-
}
|
|
1738
|
-
default:
|
|
1739
|
-
if (postData.text) {
|
|
1740
|
-
push(`req.send(${stringifyObject9__default.default(postData.text, { indent: opts.indent })});`);
|
|
1741
|
-
blank();
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
if (includeFS) {
|
|
1745
|
-
unshift("const fs = require('fs');");
|
|
1746
|
-
}
|
|
1747
|
-
push("req.end(function (res) {");
|
|
1748
|
-
push("if (res.error) throw new Error(res.error);", 1);
|
|
1749
|
-
blank();
|
|
1750
|
-
push("console.log(res.body);", 1);
|
|
1751
|
-
push("});");
|
|
1752
|
-
return join();
|
|
1753
|
-
}
|
|
1754
|
-
};
|
|
1755
1559
|
|
|
1756
1560
|
// src/targets/node/target.ts
|
|
1757
1561
|
var node = {
|
|
1758
1562
|
info: {
|
|
1759
1563
|
key: "node",
|
|
1760
1564
|
title: "Node.js",
|
|
1761
|
-
default: "
|
|
1565
|
+
default: "fetch",
|
|
1762
1566
|
cli: "node %s"
|
|
1763
1567
|
},
|
|
1764
1568
|
clientsById: {
|
|
1765
1569
|
native: native3,
|
|
1766
|
-
request,
|
|
1767
|
-
unirest: unirest2,
|
|
1768
1570
|
axios: axios2,
|
|
1769
1571
|
fetch: fetch2
|
|
1770
1572
|
}
|
|
@@ -1942,7 +1744,7 @@ var cohttp = {
|
|
|
1942
1744
|
link: "https://github.com/mirage/ocaml-cohttp",
|
|
1943
1745
|
description: "Cohttp is a very lightweight HTTP server using Lwt or Async for OCaml",
|
|
1944
1746
|
extname: ".ml",
|
|
1945
|
-
installation: "opam install cohttp-lwt-unix cohttp-async"
|
|
1747
|
+
installation: () => "opam install cohttp-lwt-unix cohttp-async"
|
|
1946
1748
|
},
|
|
1947
1749
|
convert: ({ fullUrl, allHeaders, postData, method }, options) => {
|
|
1948
1750
|
const opts = {
|
|
@@ -2189,7 +1991,7 @@ var guzzle = {
|
|
|
2189
1991
|
link: "http://docs.guzzlephp.org/en/stable/",
|
|
2190
1992
|
description: "PHP with Guzzle",
|
|
2191
1993
|
extname: ".php",
|
|
2192
|
-
installation: "composer require guzzlehttp/guzzle"
|
|
1994
|
+
installation: () => "composer require guzzlehttp/guzzle"
|
|
2193
1995
|
},
|
|
2194
1996
|
convert: ({ postData, fullUrl, method, cookies, headersObj }, options) => {
|
|
2195
1997
|
const opts = {
|
|
@@ -2250,9 +2052,7 @@ var guzzle = {
|
|
|
2250
2052
|
requestPush(`'body' => ${convertType(postData.text)},`, 1);
|
|
2251
2053
|
}
|
|
2252
2054
|
}
|
|
2253
|
-
const headers = Object.keys(headersObj).sort().map(
|
|
2254
|
-
return `${opts.indent}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`;
|
|
2255
|
-
});
|
|
2055
|
+
const headers = Object.keys(headersObj).sort().map((key) => `${opts.indent}${opts.indent}'${key}' => '${escapeForSingleQuotes(headersObj[key])}',`);
|
|
2256
2056
|
const cookieString = cookies.map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`).join("; ");
|
|
2257
2057
|
if (cookieString.length) {
|
|
2258
2058
|
headers.push(`${opts.indent}${opts.indent}'cookie' => '${escapeForSingleQuotes(cookieString)}',`);
|
|
@@ -2615,7 +2415,7 @@ var requests = {
|
|
|
2615
2415
|
link: "http://docs.python-requests.org/en/latest/api/#requests.request",
|
|
2616
2416
|
description: "Requests HTTP library",
|
|
2617
2417
|
extname: ".py",
|
|
2618
|
-
installation: "python -m pip install requests"
|
|
2418
|
+
installation: () => "python -m pip install requests"
|
|
2619
2419
|
},
|
|
2620
2420
|
convert: ({ fullUrl, postData, allHeaders, method }, options) => {
|
|
2621
2421
|
const opts = {
|
|
@@ -2715,22 +2515,22 @@ var requests = {
|
|
|
2715
2515
|
push("}");
|
|
2716
2516
|
blank();
|
|
2717
2517
|
}
|
|
2718
|
-
let
|
|
2518
|
+
let request = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
|
|
2719
2519
|
if (hasPayload) {
|
|
2720
2520
|
if (jsonPayload) {
|
|
2721
|
-
|
|
2521
|
+
request += ", json=payload";
|
|
2722
2522
|
} else {
|
|
2723
|
-
|
|
2523
|
+
request += ", data=payload";
|
|
2724
2524
|
}
|
|
2725
2525
|
}
|
|
2726
2526
|
if (hasFiles) {
|
|
2727
|
-
|
|
2527
|
+
request += ", files=files";
|
|
2728
2528
|
}
|
|
2729
2529
|
if (headerCount > 0) {
|
|
2730
|
-
|
|
2530
|
+
request += ", headers=headers";
|
|
2731
2531
|
}
|
|
2732
|
-
|
|
2733
|
-
push(
|
|
2532
|
+
request += ")";
|
|
2533
|
+
push(request);
|
|
2734
2534
|
blank();
|
|
2735
2535
|
push("print(response.text)");
|
|
2736
2536
|
return join();
|
|
@@ -2815,22 +2615,22 @@ var httr = {
|
|
|
2815
2615
|
const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
|
|
2816
2616
|
const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
|
|
2817
2617
|
const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
|
|
2818
|
-
let
|
|
2618
|
+
let request = `response <- VERB("${method}", url`;
|
|
2819
2619
|
if (payload) {
|
|
2820
|
-
|
|
2620
|
+
request += ", body = payload";
|
|
2821
2621
|
}
|
|
2822
2622
|
if (queryString.length) {
|
|
2823
|
-
|
|
2623
|
+
request += ", query = queryString";
|
|
2824
2624
|
}
|
|
2825
2625
|
const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
|
|
2826
2626
|
if (headerAdditions) {
|
|
2827
|
-
|
|
2627
|
+
request += `, ${headerAdditions}`;
|
|
2828
2628
|
}
|
|
2829
2629
|
if (postData.text || postData.jsonObj || postData.params) {
|
|
2830
|
-
|
|
2630
|
+
request += ", encode = encode";
|
|
2831
2631
|
}
|
|
2832
|
-
|
|
2833
|
-
push(
|
|
2632
|
+
request += ")";
|
|
2633
|
+
push(request);
|
|
2834
2634
|
blank();
|
|
2835
2635
|
push('content(response, "text")');
|
|
2836
2636
|
return join();
|
|
@@ -3019,18 +2819,16 @@ ${indent}` : " "
|
|
|
3019
2819
|
case "application/x-www-form-urlencoded":
|
|
3020
2820
|
if (postData.params) {
|
|
3021
2821
|
postData.params.forEach((param) => {
|
|
3022
|
-
const unencoded = param.name;
|
|
3023
2822
|
const encoded = encodeURIComponent(param.name);
|
|
3024
|
-
const
|
|
3025
|
-
const
|
|
3026
|
-
const flag = binary ? "--data-binary" : needsEncoding ? "--data-urlencode" : arg("data");
|
|
2823
|
+
const name = encoded !== param.name ? encoded : param.name;
|
|
2824
|
+
const flag = binary ? "--data-binary" : "--data-urlencode";
|
|
3027
2825
|
push(`${flag} ${quote(`${name}=${param.value}`)}`);
|
|
3028
2826
|
});
|
|
3029
2827
|
} else {
|
|
3030
2828
|
push(`${binary ? "--data-binary" : arg("data")} ${quote(postData.text)}`);
|
|
3031
2829
|
}
|
|
3032
2830
|
break;
|
|
3033
|
-
default:
|
|
2831
|
+
default: {
|
|
3034
2832
|
if (!postData.text) {
|
|
3035
2833
|
break;
|
|
3036
2834
|
}
|
|
@@ -3057,13 +2855,14 @@ ${JSON.stringify(jsonPayload, null, indentJSON)}
|
|
|
3057
2855
|
'`
|
|
3058
2856
|
);
|
|
3059
2857
|
}
|
|
3060
|
-
} catch
|
|
2858
|
+
} catch {
|
|
3061
2859
|
}
|
|
3062
2860
|
}
|
|
3063
2861
|
}
|
|
3064
2862
|
if (!builtPayload) {
|
|
3065
2863
|
push(`${binary ? "--data-binary" : arg("data")} ${quote(postData.text)}`);
|
|
3066
2864
|
}
|
|
2865
|
+
}
|
|
3067
2866
|
}
|
|
3068
2867
|
return join();
|
|
3069
2868
|
}
|
|
@@ -3077,7 +2876,7 @@ var httpie = {
|
|
|
3077
2876
|
link: "http://httpie.org/",
|
|
3078
2877
|
description: "a CLI, cURL-like tool for humans",
|
|
3079
2878
|
extname: ".sh",
|
|
3080
|
-
installation: "brew install httpie"
|
|
2879
|
+
installation: () => "brew install httpie"
|
|
3081
2880
|
},
|
|
3082
2881
|
convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }, options) => {
|
|
3083
2882
|
const opts = {
|
|
@@ -3146,7 +2945,7 @@ ${opts.indent}` : " "
|
|
|
3146
2945
|
push(`${key}:${quote(allHeaders[key])}`);
|
|
3147
2946
|
});
|
|
3148
2947
|
if (postData.mimeType === "application/x-www-form-urlencoded") {
|
|
3149
|
-
if (postData.params
|
|
2948
|
+
if (postData.params?.length) {
|
|
3150
2949
|
flags.push(opts.short ? "-f" : "--form");
|
|
3151
2950
|
postData.params.forEach((param) => {
|
|
3152
2951
|
push(`${param.name}=${quote(param.value)}`);
|
|
@@ -3302,7 +3101,9 @@ var urlsession = {
|
|
|
3302
3101
|
const parameters = postData.params.map((p) => `"${p.name}": "${p.value}"`);
|
|
3303
3102
|
if (opts.pretty) {
|
|
3304
3103
|
push("let parameters = [");
|
|
3305
|
-
parameters.forEach((param) =>
|
|
3104
|
+
parameters.forEach((param) => {
|
|
3105
|
+
push(`${param},`, 1);
|
|
3106
|
+
});
|
|
3306
3107
|
push("]");
|
|
3307
3108
|
} else {
|
|
3308
3109
|
push(`let parameters = [${parameters.join(", ")}]`);
|