@readme/httpsnippet 10.1.0 → 10.1.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/README.md +2 -2
- package/dist/{chunk-452Q5GGQ.js → chunk-532RKFLR.js} +254 -53
- package/dist/chunk-532RKFLR.js.map +1 -0
- package/dist/index.cjs +294 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/targets/index.cjs +253 -52
- package/dist/targets/index.cjs.map +1 -1
- package/dist/targets/index.js +1 -1
- package/package.json +3 -1
- package/dist/chunk-452Q5GGQ.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { reducer } from './chunk-KT7MO6Z4.js';
|
|
2
|
-
import { targets, getHeaderName } from './chunk-
|
|
3
|
-
export { addClientPlugin, addTarget, addTargetClient } from './chunk-
|
|
2
|
+
import { targets, getHeaderName } from './chunk-532RKFLR.js';
|
|
3
|
+
export { addClientPlugin, addTarget, addTargetClient } from './chunk-532RKFLR.js';
|
|
4
4
|
import './chunk-Y7NI4MMY.js';
|
|
5
5
|
import { parse, format } from 'url';
|
|
6
6
|
import { stringify } from 'qs';
|
package/dist/targets/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var stringifyObject9 = require('stringify-object');
|
|
4
4
|
|
|
5
5
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var stringifyObject9__default = /*#__PURE__*/_interopDefault(stringifyObject9);
|
|
8
8
|
|
|
9
9
|
// src/helpers/code-builder.ts
|
|
10
10
|
var DEFAULT_INDENTATION_CHARACTER = "";
|
|
@@ -959,7 +959,7 @@ var axios = {
|
|
|
959
959
|
requestOptions.data = postData.text;
|
|
960
960
|
}
|
|
961
961
|
}
|
|
962
|
-
const optionString =
|
|
962
|
+
const optionString = stringifyObject9__default.default(requestOptions, {
|
|
963
963
|
indent: " ",
|
|
964
964
|
inlineCharacterLimit: 80
|
|
965
965
|
}).replace('"[form]"', "form");
|
|
@@ -967,8 +967,12 @@ var axios = {
|
|
|
967
967
|
blank();
|
|
968
968
|
push("axios");
|
|
969
969
|
push(".request(options)", 1);
|
|
970
|
-
push(".then(
|
|
971
|
-
push(".
|
|
970
|
+
push(".then(function (response) {", 1);
|
|
971
|
+
push("console.log(response.data);", 2);
|
|
972
|
+
push("})", 1);
|
|
973
|
+
push(".catch(function (error) {", 1);
|
|
974
|
+
push("console.error(error);", 2);
|
|
975
|
+
push("});", 1);
|
|
972
976
|
return join();
|
|
973
977
|
}
|
|
974
978
|
};
|
|
@@ -1028,7 +1032,7 @@ var fetch = {
|
|
|
1028
1032
|
delete options.headers;
|
|
1029
1033
|
}
|
|
1030
1034
|
push(
|
|
1031
|
-
`const options = ${
|
|
1035
|
+
`const options = ${stringifyObject9__default.default(options, {
|
|
1032
1036
|
indent: opts.indent,
|
|
1033
1037
|
inlineCharacterLimit: 80,
|
|
1034
1038
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult
|
|
@@ -1052,8 +1056,8 @@ var fetch = {
|
|
|
1052
1056
|
blank();
|
|
1053
1057
|
}
|
|
1054
1058
|
push(`fetch('${fullUrl}', options)`);
|
|
1055
|
-
push(".then(
|
|
1056
|
-
push(".then(
|
|
1059
|
+
push(".then(response => response.json())", 1);
|
|
1060
|
+
push(".then(response => console.log(response))", 1);
|
|
1057
1061
|
push(".catch(err => console.error(err));", 1);
|
|
1058
1062
|
return join();
|
|
1059
1063
|
}
|
|
@@ -1114,11 +1118,11 @@ var jquery = {
|
|
|
1114
1118
|
settings.data = postData.text;
|
|
1115
1119
|
}
|
|
1116
1120
|
}
|
|
1117
|
-
const stringifiedSettings =
|
|
1121
|
+
const stringifiedSettings = stringifyObject9__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
|
|
1118
1122
|
push(`const settings = ${stringifiedSettings};`);
|
|
1119
1123
|
blank();
|
|
1120
|
-
push("$.ajax(settings).done(
|
|
1121
|
-
push("console.log(
|
|
1124
|
+
push("$.ajax(settings).done(function (response) {");
|
|
1125
|
+
push("console.log(response);", 1);
|
|
1122
1126
|
push("});");
|
|
1123
1127
|
return join();
|
|
1124
1128
|
}
|
|
@@ -1141,7 +1145,7 @@ var xhr = {
|
|
|
1141
1145
|
switch (postData.mimeType) {
|
|
1142
1146
|
case "application/json":
|
|
1143
1147
|
push(
|
|
1144
|
-
`const data = JSON.stringify(${
|
|
1148
|
+
`const data = JSON.stringify(${stringifyObject9__default.default(postData.jsonObj, {
|
|
1145
1149
|
indent: opts.indent
|
|
1146
1150
|
})});`
|
|
1147
1151
|
);
|
|
@@ -1195,7 +1199,7 @@ var javascript = {
|
|
|
1195
1199
|
info: {
|
|
1196
1200
|
key: "javascript",
|
|
1197
1201
|
title: "JavaScript",
|
|
1198
|
-
default: "
|
|
1202
|
+
default: "xhr"
|
|
1199
1203
|
},
|
|
1200
1204
|
clientsById: {
|
|
1201
1205
|
xhr,
|
|
@@ -1334,7 +1338,7 @@ var axios2 = {
|
|
|
1334
1338
|
title: "Axios",
|
|
1335
1339
|
link: "https://github.com/axios/axios",
|
|
1336
1340
|
description: "Promise based HTTP client for the browser and node.js",
|
|
1337
|
-
extname: ".
|
|
1341
|
+
extname: ".cjs",
|
|
1338
1342
|
installation: "npm install axios --save"
|
|
1339
1343
|
},
|
|
1340
1344
|
convert: ({ method, fullUrl, allHeaders, postData }, options) => {
|
|
@@ -1343,8 +1347,7 @@ var axios2 = {
|
|
|
1343
1347
|
...options
|
|
1344
1348
|
};
|
|
1345
1349
|
const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1346
|
-
push("
|
|
1347
|
-
blank();
|
|
1350
|
+
push("const axios = require('axios');");
|
|
1348
1351
|
const reqOpts = {
|
|
1349
1352
|
method,
|
|
1350
1353
|
url: fullUrl
|
|
@@ -1355,6 +1358,8 @@ var axios2 = {
|
|
|
1355
1358
|
switch (postData.mimeType) {
|
|
1356
1359
|
case "application/x-www-form-urlencoded":
|
|
1357
1360
|
if (postData.params) {
|
|
1361
|
+
push("const { URLSearchParams } = require('url');");
|
|
1362
|
+
blank();
|
|
1358
1363
|
push("const encodedParams = new URLSearchParams();");
|
|
1359
1364
|
postData.params.forEach((param) => {
|
|
1360
1365
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
@@ -1365,32 +1370,39 @@ var axios2 = {
|
|
|
1365
1370
|
}
|
|
1366
1371
|
break;
|
|
1367
1372
|
case "application/json":
|
|
1373
|
+
blank();
|
|
1368
1374
|
if (postData.jsonObj) {
|
|
1369
1375
|
reqOpts.data = postData.jsonObj;
|
|
1370
1376
|
}
|
|
1371
1377
|
break;
|
|
1372
1378
|
default:
|
|
1379
|
+
blank();
|
|
1373
1380
|
if (postData.text) {
|
|
1374
1381
|
reqOpts.data = postData.text;
|
|
1375
1382
|
}
|
|
1376
1383
|
}
|
|
1377
|
-
const stringifiedOptions =
|
|
1384
|
+
const stringifiedOptions = stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
|
|
1378
1385
|
push(`const options = ${stringifiedOptions};`);
|
|
1379
1386
|
blank();
|
|
1380
1387
|
push("axios");
|
|
1381
1388
|
push(".request(options)", 1);
|
|
1382
|
-
push(".then(
|
|
1383
|
-
push(".
|
|
1389
|
+
push(".then(function (response) {", 1);
|
|
1390
|
+
push("console.log(response.data);", 2);
|
|
1391
|
+
push("})", 1);
|
|
1392
|
+
push(".catch(function (error) {", 1);
|
|
1393
|
+
push("console.error(error);", 2);
|
|
1394
|
+
push("});", 1);
|
|
1384
1395
|
return join();
|
|
1385
1396
|
}
|
|
1386
1397
|
};
|
|
1387
1398
|
var fetch2 = {
|
|
1388
1399
|
info: {
|
|
1389
1400
|
key: "fetch",
|
|
1390
|
-
title: "
|
|
1391
|
-
link: "https://
|
|
1392
|
-
description: "
|
|
1393
|
-
extname: ".
|
|
1401
|
+
title: "Fetch",
|
|
1402
|
+
link: "https://github.com/bitinn/node-fetch",
|
|
1403
|
+
description: "Simplified HTTP node-fetch client",
|
|
1404
|
+
extname: ".cjs",
|
|
1405
|
+
installation: "npm install node-fetch@2 --save"
|
|
1394
1406
|
},
|
|
1395
1407
|
convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1396
1408
|
const opts = {
|
|
@@ -1399,6 +1411,7 @@ var fetch2 = {
|
|
|
1399
1411
|
};
|
|
1400
1412
|
let includeFS = false;
|
|
1401
1413
|
const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
|
|
1414
|
+
push("const fetch = require('node-fetch');");
|
|
1402
1415
|
const url = fullUrl;
|
|
1403
1416
|
const reqOpts = {
|
|
1404
1417
|
method
|
|
@@ -1408,12 +1421,13 @@ var fetch2 = {
|
|
|
1408
1421
|
}
|
|
1409
1422
|
switch (postData.mimeType) {
|
|
1410
1423
|
case "application/x-www-form-urlencoded":
|
|
1424
|
+
unshift("const { URLSearchParams } = require('url');");
|
|
1411
1425
|
push("const encodedParams = new URLSearchParams();");
|
|
1426
|
+
blank();
|
|
1412
1427
|
postData.params?.forEach((param) => {
|
|
1413
1428
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
1414
1429
|
});
|
|
1415
1430
|
reqOpts.body = "encodedParams";
|
|
1416
|
-
blank();
|
|
1417
1431
|
break;
|
|
1418
1432
|
case "application/json":
|
|
1419
1433
|
if (postData.jsonObj) {
|
|
@@ -1428,7 +1442,9 @@ var fetch2 = {
|
|
|
1428
1442
|
if (contentTypeHeader) {
|
|
1429
1443
|
delete headersObj[contentTypeHeader];
|
|
1430
1444
|
}
|
|
1445
|
+
unshift("const FormData = require('form-data');");
|
|
1431
1446
|
push("const formData = new FormData();");
|
|
1447
|
+
blank();
|
|
1432
1448
|
postData.params.forEach((param) => {
|
|
1433
1449
|
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1434
1450
|
push(`formData.append('${param.name}', '${param.value}');`);
|
|
@@ -1436,13 +1452,9 @@ var fetch2 = {
|
|
|
1436
1452
|
}
|
|
1437
1453
|
if (param.fileName) {
|
|
1438
1454
|
includeFS = true;
|
|
1439
|
-
push(
|
|
1440
|
-
`formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`
|
|
1441
|
-
);
|
|
1455
|
+
push(`formData.append('${param.name}', fs.createReadStream('${param.fileName}'));`);
|
|
1442
1456
|
}
|
|
1443
1457
|
});
|
|
1444
|
-
reqOpts.body = "formData";
|
|
1445
|
-
blank();
|
|
1446
1458
|
break;
|
|
1447
1459
|
default:
|
|
1448
1460
|
if (postData.text) {
|
|
@@ -1458,11 +1470,12 @@ var fetch2 = {
|
|
|
1458
1470
|
reqOpts.headers.cookie = cookiesString;
|
|
1459
1471
|
}
|
|
1460
1472
|
}
|
|
1473
|
+
blank();
|
|
1461
1474
|
push(`const url = '${url}';`);
|
|
1462
1475
|
if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
|
|
1463
1476
|
delete reqOpts.headers;
|
|
1464
1477
|
}
|
|
1465
|
-
const stringifiedOptions =
|
|
1478
|
+
const stringifiedOptions = stringifyObject9__default.default(reqOpts, {
|
|
1466
1479
|
indent: " ",
|
|
1467
1480
|
inlineCharacterLimit: 80,
|
|
1468
1481
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
|
|
@@ -1478,13 +1491,17 @@ var fetch2 = {
|
|
|
1478
1491
|
push(`const options = ${stringifiedOptions};`);
|
|
1479
1492
|
blank();
|
|
1480
1493
|
if (includeFS) {
|
|
1481
|
-
unshift("
|
|
1494
|
+
unshift("const fs = require('fs');");
|
|
1495
|
+
}
|
|
1496
|
+
if (postData.params && postData.mimeType === "multipart/form-data") {
|
|
1497
|
+
push("options.body = formData;");
|
|
1498
|
+
blank();
|
|
1482
1499
|
}
|
|
1483
1500
|
push("fetch(url, options)");
|
|
1484
1501
|
push(".then(res => res.json())", 1);
|
|
1485
1502
|
push(".then(json => console.log(json))", 1);
|
|
1486
|
-
push(".catch(err => console.error(err));", 1);
|
|
1487
|
-
return join().replace(/'encodedParams'/, "encodedParams").replace(/
|
|
1503
|
+
push(".catch(err => console.error('error:' + err));", 1);
|
|
1504
|
+
return join().replace(/'encodedParams'/, "encodedParams").replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
|
|
1488
1505
|
}
|
|
1489
1506
|
};
|
|
1490
1507
|
var native3 = {
|
|
@@ -1507,7 +1524,7 @@ var native3 = {
|
|
|
1507
1524
|
};
|
|
1508
1525
|
push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
|
|
1509
1526
|
blank();
|
|
1510
|
-
push(`const options = ${
|
|
1527
|
+
push(`const options = ${stringifyObject9__default.default(reqOpts, { indent })};`);
|
|
1511
1528
|
blank();
|
|
1512
1529
|
push("const req = http.request(options, function (res) {");
|
|
1513
1530
|
push("const chunks = [];", 1);
|
|
@@ -1527,7 +1544,7 @@ var native3 = {
|
|
|
1527
1544
|
if (postData.paramsObj) {
|
|
1528
1545
|
unshift("const qs = require('querystring');");
|
|
1529
1546
|
push(
|
|
1530
|
-
`req.write(qs.stringify(${
|
|
1547
|
+
`req.write(qs.stringify(${stringifyObject9__default.default(postData.paramsObj, {
|
|
1531
1548
|
indent: " ",
|
|
1532
1549
|
inlineCharacterLimit: 80
|
|
1533
1550
|
})}));`
|
|
@@ -1537,7 +1554,7 @@ var native3 = {
|
|
|
1537
1554
|
case "application/json":
|
|
1538
1555
|
if (postData.jsonObj) {
|
|
1539
1556
|
push(
|
|
1540
|
-
`req.write(JSON.stringify(${
|
|
1557
|
+
`req.write(JSON.stringify(${stringifyObject9__default.default(postData.jsonObj, {
|
|
1541
1558
|
indent: " ",
|
|
1542
1559
|
inlineCharacterLimit: 80
|
|
1543
1560
|
})}));`
|
|
@@ -1546,24 +1563,208 @@ var native3 = {
|
|
|
1546
1563
|
break;
|
|
1547
1564
|
default:
|
|
1548
1565
|
if (postData.text) {
|
|
1549
|
-
push(`req.write(${
|
|
1566
|
+
push(`req.write(${stringifyObject9__default.default(postData.text, { indent })});`);
|
|
1550
1567
|
}
|
|
1551
1568
|
}
|
|
1552
1569
|
push("req.end();");
|
|
1553
1570
|
return join();
|
|
1554
1571
|
}
|
|
1555
1572
|
};
|
|
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
|
+
};
|
|
1556
1755
|
|
|
1557
1756
|
// src/targets/node/target.ts
|
|
1558
1757
|
var node = {
|
|
1559
1758
|
info: {
|
|
1560
1759
|
key: "node",
|
|
1561
1760
|
title: "Node.js",
|
|
1562
|
-
default: "
|
|
1761
|
+
default: "native",
|
|
1563
1762
|
cli: "node %s"
|
|
1564
1763
|
},
|
|
1565
1764
|
clientsById: {
|
|
1566
1765
|
native: native3,
|
|
1766
|
+
request,
|
|
1767
|
+
unirest: unirest2,
|
|
1567
1768
|
axios: axios2,
|
|
1568
1769
|
fetch: fetch2
|
|
1569
1770
|
}
|
|
@@ -2514,22 +2715,22 @@ var requests = {
|
|
|
2514
2715
|
push("}");
|
|
2515
2716
|
blank();
|
|
2516
2717
|
}
|
|
2517
|
-
let
|
|
2718
|
+
let request2 = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
|
|
2518
2719
|
if (hasPayload) {
|
|
2519
2720
|
if (jsonPayload) {
|
|
2520
|
-
|
|
2721
|
+
request2 += ", json=payload";
|
|
2521
2722
|
} else {
|
|
2522
|
-
|
|
2723
|
+
request2 += ", data=payload";
|
|
2523
2724
|
}
|
|
2524
2725
|
}
|
|
2525
2726
|
if (hasFiles) {
|
|
2526
|
-
|
|
2727
|
+
request2 += ", files=files";
|
|
2527
2728
|
}
|
|
2528
2729
|
if (headerCount > 0) {
|
|
2529
|
-
|
|
2730
|
+
request2 += ", headers=headers";
|
|
2530
2731
|
}
|
|
2531
|
-
|
|
2532
|
-
push(
|
|
2732
|
+
request2 += ")";
|
|
2733
|
+
push(request2);
|
|
2533
2734
|
blank();
|
|
2534
2735
|
push("print(response.text)");
|
|
2535
2736
|
return join();
|
|
@@ -2614,22 +2815,22 @@ var httr = {
|
|
|
2614
2815
|
const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
|
|
2615
2816
|
const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
|
|
2616
2817
|
const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
|
|
2617
|
-
let
|
|
2818
|
+
let request2 = `response <- VERB("${method}", url`;
|
|
2618
2819
|
if (payload) {
|
|
2619
|
-
|
|
2820
|
+
request2 += ", body = payload";
|
|
2620
2821
|
}
|
|
2621
2822
|
if (queryString.length) {
|
|
2622
|
-
|
|
2823
|
+
request2 += ", query = queryString";
|
|
2623
2824
|
}
|
|
2624
2825
|
const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
|
|
2625
2826
|
if (headerAdditions) {
|
|
2626
|
-
|
|
2827
|
+
request2 += `, ${headerAdditions}`;
|
|
2627
2828
|
}
|
|
2628
2829
|
if (postData.text || postData.jsonObj || postData.params) {
|
|
2629
|
-
|
|
2830
|
+
request2 += ", encode = encode";
|
|
2630
2831
|
}
|
|
2631
|
-
|
|
2632
|
-
push(
|
|
2832
|
+
request2 += ")";
|
|
2833
|
+
push(request2);
|
|
2633
2834
|
blank();
|
|
2634
2835
|
push('content(response, "text")');
|
|
2635
2836
|
return join();
|