@readme/httpsnippet 10.0.5 → 10.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-QBICEG2V.js → chunk-452Q5GGQ.js} +57 -262
- package/dist/chunk-452Q5GGQ.js.map +1 -0
- package/dist/chunk-KT7MO6Z4.js +1 -1
- package/dist/chunk-KT7MO6Z4.js.map +1 -1
- package/dist/chunk-Y7NI4MMY.js +1 -1
- package/dist/chunk-Y7NI4MMY.js.map +1 -1
- package/dist/helpers/code-builder.cjs +1 -1
- package/dist/helpers/code-builder.cjs.map +1 -1
- package/dist/helpers/code-builder.js +1 -1
- package/dist/helpers/code-builder.js.map +1 -1
- package/dist/helpers/reducer.cjs +1 -1
- package/dist/helpers/reducer.cjs.map +1 -1
- package/dist/helpers/reducer.js +1 -1
- package/dist/helpers/reducer.js.map +1 -1
- package/dist/{index-BTuTGf5t.d.ts → index-Bi-oJSCB.d.ts} +6 -6
- package/dist/{index-C-fCLOHv.d.cts → index-CM3ebXTM.d.cts} +6 -6
- package/dist/index.cjs +98 -303
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/targets/index.cjs +57 -262
- package/dist/targets/index.cjs.map +1 -1
- package/dist/targets/index.d.cts +1 -1
- package/dist/targets/index.d.ts +1 -1
- package/dist/targets/index.js +2 -2
- package/dist/targets/index.js.map +1 -1
- package/package.json +4 -6
- package/dist/chunk-QBICEG2V.js.map +0 -1
package/README.md
CHANGED
|
@@ -109,8 +109,8 @@ console.log(
|
|
|
109
109
|
}),
|
|
110
110
|
);
|
|
111
111
|
|
|
112
|
-
// generate Node.js:
|
|
113
|
-
console.log(snippet.convert('node', '
|
|
112
|
+
// generate Node.js: Axios output
|
|
113
|
+
console.log(snippet.convert('node', 'axios'));
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
### addTarget(target)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CodeBuilder } from './chunk-Y7NI4MMY.js';
|
|
2
|
-
import
|
|
2
|
+
import stringifyObject7 from 'stringify-object';
|
|
3
3
|
|
|
4
4
|
// src/helpers/escape.ts
|
|
5
5
|
function escapeString(rawValue, options = {}) {
|
|
@@ -464,8 +464,7 @@ var restsharp = {
|
|
|
464
464
|
});
|
|
465
465
|
switch (postData.mimeType) {
|
|
466
466
|
case "multipart/form-data":
|
|
467
|
-
if (!postData.params)
|
|
468
|
-
break;
|
|
467
|
+
if (!postData.params) break;
|
|
469
468
|
postData.params.forEach((param) => {
|
|
470
469
|
if (param.fileName) {
|
|
471
470
|
push(`request.AddFile("${param.name}", "${param.fileName}");`);
|
|
@@ -475,22 +474,19 @@ var restsharp = {
|
|
|
475
474
|
});
|
|
476
475
|
break;
|
|
477
476
|
case "application/x-www-form-urlencoded":
|
|
478
|
-
if (!postData.params)
|
|
479
|
-
break;
|
|
477
|
+
if (!postData.params) break;
|
|
480
478
|
postData.params.forEach((param) => {
|
|
481
479
|
push(`request.AddParameter("${param.name}", "${param.value}");`);
|
|
482
480
|
});
|
|
483
481
|
break;
|
|
484
482
|
case "application/json": {
|
|
485
|
-
if (!postData.text)
|
|
486
|
-
break;
|
|
483
|
+
if (!postData.text) break;
|
|
487
484
|
const text = JSON.stringify(postData.text);
|
|
488
485
|
push(`request.AddJsonBody(${text}, false);`);
|
|
489
486
|
break;
|
|
490
487
|
}
|
|
491
488
|
default:
|
|
492
|
-
if (!postData.text)
|
|
493
|
-
break;
|
|
489
|
+
if (!postData.text) break;
|
|
494
490
|
push(`request.AddStringBody("${postData.text}", "${postData.mimeType}");`);
|
|
495
491
|
}
|
|
496
492
|
push(`var response = await client.${title(method)}Async(request);
|
|
@@ -898,7 +894,7 @@ var axios = {
|
|
|
898
894
|
requestOptions.data = postData.text;
|
|
899
895
|
}
|
|
900
896
|
}
|
|
901
|
-
const optionString =
|
|
897
|
+
const optionString = stringifyObject7(requestOptions, {
|
|
902
898
|
indent: " ",
|
|
903
899
|
inlineCharacterLimit: 80
|
|
904
900
|
}).replace('"[form]"', "form");
|
|
@@ -906,12 +902,8 @@ var axios = {
|
|
|
906
902
|
blank();
|
|
907
903
|
push("axios");
|
|
908
904
|
push(".request(options)", 1);
|
|
909
|
-
push(".then(
|
|
910
|
-
push("console.
|
|
911
|
-
push("})", 1);
|
|
912
|
-
push(".catch(function (error) {", 1);
|
|
913
|
-
push("console.error(error);", 2);
|
|
914
|
-
push("});", 1);
|
|
905
|
+
push(".then(res => console.log(res.data))", 1);
|
|
906
|
+
push(".catch(err => console.error(err));", 1);
|
|
915
907
|
return join();
|
|
916
908
|
}
|
|
917
909
|
};
|
|
@@ -971,7 +963,7 @@ var fetch = {
|
|
|
971
963
|
delete options.headers;
|
|
972
964
|
}
|
|
973
965
|
push(
|
|
974
|
-
`const options = ${
|
|
966
|
+
`const options = ${stringifyObject7(options, {
|
|
975
967
|
indent: opts.indent,
|
|
976
968
|
inlineCharacterLimit: 80,
|
|
977
969
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult
|
|
@@ -995,8 +987,8 @@ var fetch = {
|
|
|
995
987
|
blank();
|
|
996
988
|
}
|
|
997
989
|
push(`fetch('${fullUrl}', options)`);
|
|
998
|
-
push(".then(
|
|
999
|
-
push(".then(
|
|
990
|
+
push(".then(res => res.json())", 1);
|
|
991
|
+
push(".then(res => console.log(res))", 1);
|
|
1000
992
|
push(".catch(err => console.error(err));", 1);
|
|
1001
993
|
return join();
|
|
1002
994
|
}
|
|
@@ -1057,11 +1049,11 @@ var jquery = {
|
|
|
1057
1049
|
settings.data = postData.text;
|
|
1058
1050
|
}
|
|
1059
1051
|
}
|
|
1060
|
-
const stringifiedSettings =
|
|
1052
|
+
const stringifiedSettings = stringifyObject7(settings, { indent: opts.indent }).replace("'[form]'", "form");
|
|
1061
1053
|
push(`const settings = ${stringifiedSettings};`);
|
|
1062
1054
|
blank();
|
|
1063
|
-
push("$.ajax(settings).done(
|
|
1064
|
-
push("console.log(
|
|
1055
|
+
push("$.ajax(settings).done(res => {");
|
|
1056
|
+
push("console.log(res);", 1);
|
|
1065
1057
|
push("});");
|
|
1066
1058
|
return join();
|
|
1067
1059
|
}
|
|
@@ -1084,7 +1076,7 @@ var xhr = {
|
|
|
1084
1076
|
switch (postData.mimeType) {
|
|
1085
1077
|
case "application/json":
|
|
1086
1078
|
push(
|
|
1087
|
-
`const data = JSON.stringify(${
|
|
1079
|
+
`const data = JSON.stringify(${stringifyObject7(postData.jsonObj, {
|
|
1088
1080
|
indent: opts.indent
|
|
1089
1081
|
})});`
|
|
1090
1082
|
);
|
|
@@ -1138,7 +1130,7 @@ var javascript = {
|
|
|
1138
1130
|
info: {
|
|
1139
1131
|
key: "javascript",
|
|
1140
1132
|
title: "JavaScript",
|
|
1141
|
-
default: "
|
|
1133
|
+
default: "fetch"
|
|
1142
1134
|
},
|
|
1143
1135
|
clientsById: {
|
|
1144
1136
|
xhr,
|
|
@@ -1277,7 +1269,7 @@ var axios2 = {
|
|
|
1277
1269
|
title: "Axios",
|
|
1278
1270
|
link: "https://github.com/axios/axios",
|
|
1279
1271
|
description: "Promise based HTTP client for the browser and node.js",
|
|
1280
|
-
extname: ".
|
|
1272
|
+
extname: ".js",
|
|
1281
1273
|
installation: "npm install axios --save"
|
|
1282
1274
|
},
|
|
1283
1275
|
convert: ({ method, fullUrl, allHeaders, postData }, options) => {
|
|
@@ -1286,7 +1278,8 @@ var axios2 = {
|
|
|
1286
1278
|
...options
|
|
1287
1279
|
};
|
|
1288
1280
|
const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1289
|
-
push("
|
|
1281
|
+
push("import axios from 'axios';");
|
|
1282
|
+
blank();
|
|
1290
1283
|
const reqOpts = {
|
|
1291
1284
|
method,
|
|
1292
1285
|
url: fullUrl
|
|
@@ -1297,8 +1290,6 @@ var axios2 = {
|
|
|
1297
1290
|
switch (postData.mimeType) {
|
|
1298
1291
|
case "application/x-www-form-urlencoded":
|
|
1299
1292
|
if (postData.params) {
|
|
1300
|
-
push("const { URLSearchParams } = require('url');");
|
|
1301
|
-
blank();
|
|
1302
1293
|
push("const encodedParams = new URLSearchParams();");
|
|
1303
1294
|
postData.params.forEach((param) => {
|
|
1304
1295
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
@@ -1309,39 +1300,32 @@ var axios2 = {
|
|
|
1309
1300
|
}
|
|
1310
1301
|
break;
|
|
1311
1302
|
case "application/json":
|
|
1312
|
-
blank();
|
|
1313
1303
|
if (postData.jsonObj) {
|
|
1314
1304
|
reqOpts.data = postData.jsonObj;
|
|
1315
1305
|
}
|
|
1316
1306
|
break;
|
|
1317
1307
|
default:
|
|
1318
|
-
blank();
|
|
1319
1308
|
if (postData.text) {
|
|
1320
1309
|
reqOpts.data = postData.text;
|
|
1321
1310
|
}
|
|
1322
1311
|
}
|
|
1323
|
-
const stringifiedOptions =
|
|
1312
|
+
const stringifiedOptions = stringifyObject7(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
|
|
1324
1313
|
push(`const options = ${stringifiedOptions};`);
|
|
1325
1314
|
blank();
|
|
1326
1315
|
push("axios");
|
|
1327
1316
|
push(".request(options)", 1);
|
|
1328
|
-
push(".then(
|
|
1329
|
-
push("console.
|
|
1330
|
-
push("})", 1);
|
|
1331
|
-
push(".catch(function (error) {", 1);
|
|
1332
|
-
push("console.error(error);", 2);
|
|
1333
|
-
push("});", 1);
|
|
1317
|
+
push(".then(res => console.log(res.data))", 1);
|
|
1318
|
+
push(".catch(err => console.error(err));", 1);
|
|
1334
1319
|
return join();
|
|
1335
1320
|
}
|
|
1336
1321
|
};
|
|
1337
1322
|
var fetch2 = {
|
|
1338
1323
|
info: {
|
|
1339
1324
|
key: "fetch",
|
|
1340
|
-
title: "
|
|
1341
|
-
link: "https://
|
|
1342
|
-
description: "
|
|
1343
|
-
extname: ".
|
|
1344
|
-
installation: "npm install node-fetch@2 --save"
|
|
1325
|
+
title: "fetch",
|
|
1326
|
+
link: "https://nodejs.org/docs/latest/api/globals.html#fetch",
|
|
1327
|
+
description: "Perform asynchronous HTTP requests with the Fetch API",
|
|
1328
|
+
extname: ".js"
|
|
1345
1329
|
},
|
|
1346
1330
|
convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1347
1331
|
const opts = {
|
|
@@ -1350,7 +1334,6 @@ var fetch2 = {
|
|
|
1350
1334
|
};
|
|
1351
1335
|
let includeFS = false;
|
|
1352
1336
|
const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
|
|
1353
|
-
push("const fetch = require('node-fetch');");
|
|
1354
1337
|
const url = fullUrl;
|
|
1355
1338
|
const reqOpts = {
|
|
1356
1339
|
method
|
|
@@ -1360,13 +1343,12 @@ var fetch2 = {
|
|
|
1360
1343
|
}
|
|
1361
1344
|
switch (postData.mimeType) {
|
|
1362
1345
|
case "application/x-www-form-urlencoded":
|
|
1363
|
-
unshift("const { URLSearchParams } = require('url');");
|
|
1364
1346
|
push("const encodedParams = new URLSearchParams();");
|
|
1365
|
-
blank();
|
|
1366
1347
|
postData.params?.forEach((param) => {
|
|
1367
1348
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
1368
1349
|
});
|
|
1369
1350
|
reqOpts.body = "encodedParams";
|
|
1351
|
+
blank();
|
|
1370
1352
|
break;
|
|
1371
1353
|
case "application/json":
|
|
1372
1354
|
if (postData.jsonObj) {
|
|
@@ -1381,9 +1363,7 @@ var fetch2 = {
|
|
|
1381
1363
|
if (contentTypeHeader) {
|
|
1382
1364
|
delete headersObj[contentTypeHeader];
|
|
1383
1365
|
}
|
|
1384
|
-
unshift("const FormData = require('form-data');");
|
|
1385
1366
|
push("const formData = new FormData();");
|
|
1386
|
-
blank();
|
|
1387
1367
|
postData.params.forEach((param) => {
|
|
1388
1368
|
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1389
1369
|
push(`formData.append('${param.name}', '${param.value}');`);
|
|
@@ -1391,9 +1371,13 @@ var fetch2 = {
|
|
|
1391
1371
|
}
|
|
1392
1372
|
if (param.fileName) {
|
|
1393
1373
|
includeFS = true;
|
|
1394
|
-
push(
|
|
1374
|
+
push(
|
|
1375
|
+
`formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`
|
|
1376
|
+
);
|
|
1395
1377
|
}
|
|
1396
1378
|
});
|
|
1379
|
+
reqOpts.body = "formData";
|
|
1380
|
+
blank();
|
|
1397
1381
|
break;
|
|
1398
1382
|
default:
|
|
1399
1383
|
if (postData.text) {
|
|
@@ -1409,12 +1393,11 @@ var fetch2 = {
|
|
|
1409
1393
|
reqOpts.headers.cookie = cookiesString;
|
|
1410
1394
|
}
|
|
1411
1395
|
}
|
|
1412
|
-
blank();
|
|
1413
1396
|
push(`const url = '${url}';`);
|
|
1414
1397
|
if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
|
|
1415
1398
|
delete reqOpts.headers;
|
|
1416
1399
|
}
|
|
1417
|
-
const stringifiedOptions =
|
|
1400
|
+
const stringifiedOptions = stringifyObject7(reqOpts, {
|
|
1418
1401
|
indent: " ",
|
|
1419
1402
|
inlineCharacterLimit: 80,
|
|
1420
1403
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
|
|
@@ -1430,17 +1413,13 @@ var fetch2 = {
|
|
|
1430
1413
|
push(`const options = ${stringifiedOptions};`);
|
|
1431
1414
|
blank();
|
|
1432
1415
|
if (includeFS) {
|
|
1433
|
-
unshift("
|
|
1434
|
-
}
|
|
1435
|
-
if (postData.params && postData.mimeType === "multipart/form-data") {
|
|
1436
|
-
push("options.body = formData;");
|
|
1437
|
-
blank();
|
|
1416
|
+
unshift("import fs from 'fs';\n");
|
|
1438
1417
|
}
|
|
1439
1418
|
push("fetch(url, options)");
|
|
1440
1419
|
push(".then(res => res.json())", 1);
|
|
1441
1420
|
push(".then(json => console.log(json))", 1);
|
|
1442
|
-
push(".catch(err => console.error(
|
|
1443
|
-
return join().replace(/'encodedParams'/, "encodedParams").replace(/
|
|
1421
|
+
push(".catch(err => console.error(err));", 1);
|
|
1422
|
+
return join().replace(/'encodedParams'/, "encodedParams").replace(/'formData'/, "formData");
|
|
1444
1423
|
}
|
|
1445
1424
|
};
|
|
1446
1425
|
var native3 = {
|
|
@@ -1463,7 +1442,7 @@ var native3 = {
|
|
|
1463
1442
|
};
|
|
1464
1443
|
push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
|
|
1465
1444
|
blank();
|
|
1466
|
-
push(`const options = ${
|
|
1445
|
+
push(`const options = ${stringifyObject7(reqOpts, { indent })};`);
|
|
1467
1446
|
blank();
|
|
1468
1447
|
push("const req = http.request(options, function (res) {");
|
|
1469
1448
|
push("const chunks = [];", 1);
|
|
@@ -1483,7 +1462,7 @@ var native3 = {
|
|
|
1483
1462
|
if (postData.paramsObj) {
|
|
1484
1463
|
unshift("const qs = require('querystring');");
|
|
1485
1464
|
push(
|
|
1486
|
-
`req.write(qs.stringify(${
|
|
1465
|
+
`req.write(qs.stringify(${stringifyObject7(postData.paramsObj, {
|
|
1487
1466
|
indent: " ",
|
|
1488
1467
|
inlineCharacterLimit: 80
|
|
1489
1468
|
})}));`
|
|
@@ -1493,7 +1472,7 @@ var native3 = {
|
|
|
1493
1472
|
case "application/json":
|
|
1494
1473
|
if (postData.jsonObj) {
|
|
1495
1474
|
push(
|
|
1496
|
-
`req.write(JSON.stringify(${
|
|
1475
|
+
`req.write(JSON.stringify(${stringifyObject7(postData.jsonObj, {
|
|
1497
1476
|
indent: " ",
|
|
1498
1477
|
inlineCharacterLimit: 80
|
|
1499
1478
|
})}));`
|
|
@@ -1502,208 +1481,24 @@ var native3 = {
|
|
|
1502
1481
|
break;
|
|
1503
1482
|
default:
|
|
1504
1483
|
if (postData.text) {
|
|
1505
|
-
push(`req.write(${
|
|
1484
|
+
push(`req.write(${stringifyObject7(postData.text, { indent })});`);
|
|
1506
1485
|
}
|
|
1507
1486
|
}
|
|
1508
1487
|
push("req.end();");
|
|
1509
1488
|
return join();
|
|
1510
1489
|
}
|
|
1511
1490
|
};
|
|
1512
|
-
var request = {
|
|
1513
|
-
info: {
|
|
1514
|
-
key: "request",
|
|
1515
|
-
title: "Request",
|
|
1516
|
-
link: "https://github.com/request/request",
|
|
1517
|
-
description: "Simplified HTTP request client",
|
|
1518
|
-
extname: ".cjs",
|
|
1519
|
-
installation: "npm install request --save"
|
|
1520
|
-
},
|
|
1521
|
-
convert: ({ method, url, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1522
|
-
const opts = {
|
|
1523
|
-
indent: " ",
|
|
1524
|
-
...options
|
|
1525
|
-
};
|
|
1526
|
-
let includeFS = false;
|
|
1527
|
-
const { push, blank, join, unshift, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1528
|
-
push("const request = require('request');");
|
|
1529
|
-
blank();
|
|
1530
|
-
const reqOpts = {
|
|
1531
|
-
method,
|
|
1532
|
-
url: fullUrl
|
|
1533
|
-
};
|
|
1534
|
-
if (Object.keys(headersObj).length) {
|
|
1535
|
-
reqOpts.headers = headersObj;
|
|
1536
|
-
}
|
|
1537
|
-
switch (postData.mimeType) {
|
|
1538
|
-
case "application/x-www-form-urlencoded":
|
|
1539
|
-
reqOpts.form = postData.paramsObj;
|
|
1540
|
-
break;
|
|
1541
|
-
case "application/json":
|
|
1542
|
-
if (postData.jsonObj) {
|
|
1543
|
-
reqOpts.body = postData.jsonObj;
|
|
1544
|
-
reqOpts.json = true;
|
|
1545
|
-
}
|
|
1546
|
-
break;
|
|
1547
|
-
case "multipart/form-data":
|
|
1548
|
-
if (!postData.params) {
|
|
1549
|
-
break;
|
|
1550
|
-
}
|
|
1551
|
-
reqOpts.formData = {};
|
|
1552
|
-
postData.params.forEach((param) => {
|
|
1553
|
-
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1554
|
-
reqOpts.formData[param.name] = param.value;
|
|
1555
|
-
return;
|
|
1556
|
-
}
|
|
1557
|
-
let attachment = {};
|
|
1558
|
-
if (param.fileName) {
|
|
1559
|
-
includeFS = true;
|
|
1560
|
-
attachment = {
|
|
1561
|
-
value: `fs.createReadStream(${param.fileName})`,
|
|
1562
|
-
options: {
|
|
1563
|
-
filename: param.fileName,
|
|
1564
|
-
contentType: param.contentType ? param.contentType : null
|
|
1565
|
-
}
|
|
1566
|
-
};
|
|
1567
|
-
} else if (param.value) {
|
|
1568
|
-
attachment.value = param.value;
|
|
1569
|
-
}
|
|
1570
|
-
reqOpts.formData[param.name] = attachment;
|
|
1571
|
-
});
|
|
1572
|
-
addPostProcessor((code) => code.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')"));
|
|
1573
|
-
break;
|
|
1574
|
-
default:
|
|
1575
|
-
if (postData.text) {
|
|
1576
|
-
reqOpts.body = postData.text;
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
if (cookies.length) {
|
|
1580
|
-
reqOpts.jar = "JAR";
|
|
1581
|
-
push("const jar = request.jar();");
|
|
1582
|
-
cookies.forEach(({ name, value }) => {
|
|
1583
|
-
push(`jar.setCookie(request.cookie('${encodeURIComponent(name)}=${encodeURIComponent(value)}'), '${url}');`);
|
|
1584
|
-
});
|
|
1585
|
-
blank();
|
|
1586
|
-
addPostProcessor((code) => code.replace(/'JAR'/, "jar"));
|
|
1587
|
-
}
|
|
1588
|
-
if (includeFS) {
|
|
1589
|
-
unshift("const fs = require('fs');");
|
|
1590
|
-
}
|
|
1591
|
-
push(`const options = ${stringifyObject9(reqOpts, { indent: " ", inlineCharacterLimit: 80 })};`);
|
|
1592
|
-
blank();
|
|
1593
|
-
push("request(options, function (error, response, body) {");
|
|
1594
|
-
push("if (error) throw new Error(error);", 1);
|
|
1595
|
-
blank();
|
|
1596
|
-
push("console.log(body);", 1);
|
|
1597
|
-
push("});");
|
|
1598
|
-
return join();
|
|
1599
|
-
}
|
|
1600
|
-
};
|
|
1601
|
-
var unirest2 = {
|
|
1602
|
-
info: {
|
|
1603
|
-
key: "unirest",
|
|
1604
|
-
title: "Unirest",
|
|
1605
|
-
link: "http://unirest.io/nodejs.html",
|
|
1606
|
-
description: "Lightweight HTTP Request Client Library",
|
|
1607
|
-
extname: ".cjs"
|
|
1608
|
-
},
|
|
1609
|
-
convert: ({ method, url, cookies, queryObj, postData, headersObj }, options) => {
|
|
1610
|
-
const opts = {
|
|
1611
|
-
indent: " ",
|
|
1612
|
-
...options
|
|
1613
|
-
};
|
|
1614
|
-
let includeFS = false;
|
|
1615
|
-
const { addPostProcessor, blank, join, push, unshift } = new CodeBuilder({
|
|
1616
|
-
indent: opts.indent
|
|
1617
|
-
});
|
|
1618
|
-
push("const unirest = require('unirest');");
|
|
1619
|
-
blank();
|
|
1620
|
-
push(`const req = unirest('${method}', '${url}');`);
|
|
1621
|
-
blank();
|
|
1622
|
-
if (cookies.length) {
|
|
1623
|
-
push("const CookieJar = unirest.jar();");
|
|
1624
|
-
cookies.forEach((cookie) => {
|
|
1625
|
-
push(`CookieJar.add('${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}', '${url}');`);
|
|
1626
|
-
});
|
|
1627
|
-
push("req.jar(CookieJar);");
|
|
1628
|
-
blank();
|
|
1629
|
-
}
|
|
1630
|
-
if (Object.keys(queryObj).length) {
|
|
1631
|
-
push(`req.query(${stringifyObject9(queryObj, { indent: opts.indent })});`);
|
|
1632
|
-
blank();
|
|
1633
|
-
}
|
|
1634
|
-
if (Object.keys(headersObj).length) {
|
|
1635
|
-
push(`req.headers(${stringifyObject9(headersObj, { indent: opts.indent })});`);
|
|
1636
|
-
blank();
|
|
1637
|
-
}
|
|
1638
|
-
switch (postData.mimeType) {
|
|
1639
|
-
case "application/x-www-form-urlencoded":
|
|
1640
|
-
if (postData.paramsObj) {
|
|
1641
|
-
push(`req.form(${stringifyObject9(postData.paramsObj, { indent: opts.indent })});`);
|
|
1642
|
-
blank();
|
|
1643
|
-
}
|
|
1644
|
-
break;
|
|
1645
|
-
case "application/json":
|
|
1646
|
-
if (postData.jsonObj) {
|
|
1647
|
-
push("req.type('json');");
|
|
1648
|
-
push(`req.send(${stringifyObject9(postData.jsonObj, { indent: opts.indent })});`);
|
|
1649
|
-
blank();
|
|
1650
|
-
}
|
|
1651
|
-
break;
|
|
1652
|
-
case "multipart/form-data": {
|
|
1653
|
-
if (!postData.params) {
|
|
1654
|
-
break;
|
|
1655
|
-
}
|
|
1656
|
-
const multipart = [];
|
|
1657
|
-
postData.params.forEach((param) => {
|
|
1658
|
-
const part = {};
|
|
1659
|
-
if (param.fileName && !param.value) {
|
|
1660
|
-
includeFS = true;
|
|
1661
|
-
part.body = `fs.createReadStream('${param.fileName}')`;
|
|
1662
|
-
addPostProcessor((code) => code.replace(/'fs\.createReadStream\(\\'(.+)\\'\)'/, "fs.createReadStream('$1')"));
|
|
1663
|
-
} else if (param.value) {
|
|
1664
|
-
part.body = param.value;
|
|
1665
|
-
}
|
|
1666
|
-
if (part.body) {
|
|
1667
|
-
if (param.contentType) {
|
|
1668
|
-
part["content-type"] = param.contentType;
|
|
1669
|
-
}
|
|
1670
|
-
multipart.push(part);
|
|
1671
|
-
}
|
|
1672
|
-
});
|
|
1673
|
-
push(`req.multipart(${stringifyObject9(multipart, { indent: opts.indent })});`);
|
|
1674
|
-
blank();
|
|
1675
|
-
break;
|
|
1676
|
-
}
|
|
1677
|
-
default:
|
|
1678
|
-
if (postData.text) {
|
|
1679
|
-
push(`req.send(${stringifyObject9(postData.text, { indent: opts.indent })});`);
|
|
1680
|
-
blank();
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
if (includeFS) {
|
|
1684
|
-
unshift("const fs = require('fs');");
|
|
1685
|
-
}
|
|
1686
|
-
push("req.end(function (res) {");
|
|
1687
|
-
push("if (res.error) throw new Error(res.error);", 1);
|
|
1688
|
-
blank();
|
|
1689
|
-
push("console.log(res.body);", 1);
|
|
1690
|
-
push("});");
|
|
1691
|
-
return join();
|
|
1692
|
-
}
|
|
1693
|
-
};
|
|
1694
1491
|
|
|
1695
1492
|
// src/targets/node/target.ts
|
|
1696
1493
|
var node = {
|
|
1697
1494
|
info: {
|
|
1698
1495
|
key: "node",
|
|
1699
1496
|
title: "Node.js",
|
|
1700
|
-
default: "
|
|
1497
|
+
default: "fetch",
|
|
1701
1498
|
cli: "node %s"
|
|
1702
1499
|
},
|
|
1703
1500
|
clientsById: {
|
|
1704
1501
|
native: native3,
|
|
1705
|
-
request,
|
|
1706
|
-
unirest: unirest2,
|
|
1707
1502
|
axios: axios2,
|
|
1708
1503
|
fetch: fetch2
|
|
1709
1504
|
}
|
|
@@ -2654,22 +2449,22 @@ var requests = {
|
|
|
2654
2449
|
push("}");
|
|
2655
2450
|
blank();
|
|
2656
2451
|
}
|
|
2657
|
-
let
|
|
2452
|
+
let request = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
|
|
2658
2453
|
if (hasPayload) {
|
|
2659
2454
|
if (jsonPayload) {
|
|
2660
|
-
|
|
2455
|
+
request += ", json=payload";
|
|
2661
2456
|
} else {
|
|
2662
|
-
|
|
2457
|
+
request += ", data=payload";
|
|
2663
2458
|
}
|
|
2664
2459
|
}
|
|
2665
2460
|
if (hasFiles) {
|
|
2666
|
-
|
|
2461
|
+
request += ", files=files";
|
|
2667
2462
|
}
|
|
2668
2463
|
if (headerCount > 0) {
|
|
2669
|
-
|
|
2464
|
+
request += ", headers=headers";
|
|
2670
2465
|
}
|
|
2671
|
-
|
|
2672
|
-
push(
|
|
2466
|
+
request += ")";
|
|
2467
|
+
push(request);
|
|
2673
2468
|
blank();
|
|
2674
2469
|
push("print(response.text)");
|
|
2675
2470
|
return join();
|
|
@@ -2754,22 +2549,22 @@ var httr = {
|
|
|
2754
2549
|
const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
|
|
2755
2550
|
const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
|
|
2756
2551
|
const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
|
|
2757
|
-
let
|
|
2552
|
+
let request = `response <- VERB("${method}", url`;
|
|
2758
2553
|
if (payload) {
|
|
2759
|
-
|
|
2554
|
+
request += ", body = payload";
|
|
2760
2555
|
}
|
|
2761
2556
|
if (queryString.length) {
|
|
2762
|
-
|
|
2557
|
+
request += ", query = queryString";
|
|
2763
2558
|
}
|
|
2764
2559
|
const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
|
|
2765
2560
|
if (headerAdditions) {
|
|
2766
|
-
|
|
2561
|
+
request += `, ${headerAdditions}`;
|
|
2767
2562
|
}
|
|
2768
2563
|
if (postData.text || postData.jsonObj || postData.params) {
|
|
2769
|
-
|
|
2564
|
+
request += ", encode = encode";
|
|
2770
2565
|
}
|
|
2771
|
-
|
|
2772
|
-
push(
|
|
2566
|
+
request += ")";
|
|
2567
|
+
push(request);
|
|
2773
2568
|
blank();
|
|
2774
2569
|
push('content(response, "text")');
|
|
2775
2570
|
return join();
|
|
@@ -3455,5 +3250,5 @@ var addTargetClient = (targetId, client) => {
|
|
|
3455
3250
|
};
|
|
3456
3251
|
|
|
3457
3252
|
export { addClientPlugin, addTarget, addTargetClient, getHeaderName, isClient, isTarget, targets };
|
|
3458
|
-
//# sourceMappingURL=
|
|
3459
|
-
//# sourceMappingURL=chunk-
|
|
3253
|
+
//# sourceMappingURL=chunk-452Q5GGQ.js.map
|
|
3254
|
+
//# sourceMappingURL=chunk-452Q5GGQ.js.map
|