@readme/httpsnippet 5.1.0 → 6.0.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/dist/helpers/code-builder.js +1 -1
- package/dist/helpers/form-data.js +2 -2
- package/dist/helpers/headers.js +1 -1
- package/dist/helpers/reducer.js +1 -1
- package/dist/helpers/shell.js +1 -1
- package/dist/helpers/utils.js +1 -1
- package/dist/index.js +14 -25
- package/dist/targets/c/libcurl/client.js +3 -3
- package/dist/targets/c/target.js +4 -4
- package/dist/targets/clojure/clj_http/client.js +10 -7
- package/dist/targets/clojure/target.js +4 -4
- package/dist/targets/csharp/httpclient/client.js +4 -4
- package/dist/targets/csharp/restsharp/client.js +3 -3
- package/dist/targets/csharp/target.js +4 -4
- package/dist/targets/go/native/client.js +3 -3
- package/dist/targets/go/target.js +4 -4
- package/dist/targets/http/http1.1/client.js +3 -3
- package/dist/targets/http/target.js +4 -4
- package/dist/targets/java/asynchttp/client.js +3 -3
- package/dist/targets/java/nethttp/client.js +3 -3
- package/dist/targets/java/okhttp/client.js +3 -3
- package/dist/targets/java/target.js +4 -4
- package/dist/targets/java/unirest/client.js +3 -3
- package/dist/targets/javascript/axios/client.js +6 -6
- package/dist/targets/javascript/axios/fixtures/application-form-encoded.js +5 -4
- package/dist/targets/javascript/axios/fixtures/application-json.js +4 -3
- package/dist/targets/javascript/axios/fixtures/cookies.js +4 -3
- package/dist/targets/javascript/axios/fixtures/custom-method.js +4 -3
- package/dist/targets/javascript/axios/fixtures/full.js +5 -4
- package/dist/targets/javascript/axios/fixtures/headers.js +4 -3
- package/dist/targets/javascript/axios/fixtures/http-insecure.js +4 -3
- package/dist/targets/javascript/axios/fixtures/jsonObj-multiline.js +4 -3
- package/dist/targets/javascript/axios/fixtures/jsonObj-null-value.js +4 -3
- package/dist/targets/javascript/axios/fixtures/multipart-data.js +4 -3
- package/dist/targets/javascript/axios/fixtures/multipart-file.js +4 -3
- package/dist/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +4 -3
- package/dist/targets/javascript/axios/fixtures/multipart-form-data.js +4 -3
- package/dist/targets/javascript/axios/fixtures/nested.js +4 -3
- package/dist/targets/javascript/axios/fixtures/postdata-malformed.js +4 -3
- package/dist/targets/javascript/axios/fixtures/query-encoded.js +4 -3
- package/dist/targets/javascript/axios/fixtures/query.js +4 -3
- package/dist/targets/javascript/axios/fixtures/short.js +4 -3
- package/dist/targets/javascript/axios/fixtures/text-plain.js +4 -3
- package/dist/targets/javascript/fetch/client.js +6 -6
- package/dist/targets/javascript/fetch/fixtures/application-form-encoded.d.ts +3 -3
- package/dist/targets/javascript/fetch/fixtures/application-form-encoded.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/application-json.d.ts +3 -3
- package/dist/targets/javascript/fetch/fixtures/application-json.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/cookies.d.ts +2 -2
- package/dist/targets/javascript/fetch/fixtures/cookies.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/custom-method.d.ts +1 -1
- package/dist/targets/javascript/fetch/fixtures/custom-method.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/full.d.ts +3 -3
- package/dist/targets/javascript/fetch/fixtures/full.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/headers.d.ts +2 -2
- package/dist/targets/javascript/fetch/fixtures/headers.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/http-insecure.d.ts +1 -1
- package/dist/targets/javascript/fetch/fixtures/http-insecure.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/jsonObj-multiline.d.ts +3 -3
- package/dist/targets/javascript/fetch/fixtures/jsonObj-multiline.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/jsonObj-null-value.d.ts +3 -3
- package/dist/targets/javascript/fetch/fixtures/jsonObj-null-value.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/multipart-data.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/multipart-file.d.ts +1 -1
- package/dist/targets/javascript/fetch/fixtures/multipart-file.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/multipart-form-data-no-params.d.ts +2 -2
- package/dist/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/multipart-form-data.d.ts +1 -1
- package/dist/targets/javascript/fetch/fixtures/multipart-form-data.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/nested.d.ts +1 -1
- package/dist/targets/javascript/fetch/fixtures/nested.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/postdata-malformed.d.ts +2 -2
- package/dist/targets/javascript/fetch/fixtures/postdata-malformed.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/query-encoded.d.ts +1 -1
- package/dist/targets/javascript/fetch/fixtures/query-encoded.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/query.d.ts +1 -1
- package/dist/targets/javascript/fetch/fixtures/query.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/short.d.ts +1 -1
- package/dist/targets/javascript/fetch/fixtures/short.js +2 -1
- package/dist/targets/javascript/fetch/fixtures/text-plain.d.ts +3 -3
- package/dist/targets/javascript/fetch/fixtures/text-plain.js +2 -1
- package/dist/targets/javascript/jquery/client.js +5 -5
- package/dist/targets/javascript/jquery/fixtures/application-form-encoded.d.ts +7 -7
- package/dist/targets/javascript/jquery/fixtures/application-json.d.ts +7 -7
- package/dist/targets/javascript/jquery/fixtures/cookies.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/custom-method.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/full.d.ts +6 -6
- package/dist/targets/javascript/jquery/fixtures/headers.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/http-insecure.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/jsonObj-multiline.d.ts +7 -7
- package/dist/targets/javascript/jquery/fixtures/jsonObj-null-value.d.ts +7 -7
- package/dist/targets/javascript/jquery/fixtures/multipart-data.d.ts +9 -9
- package/dist/targets/javascript/jquery/fixtures/multipart-file.d.ts +9 -9
- package/dist/targets/javascript/jquery/fixtures/multipart-form-data-no-params.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/multipart-form-data.d.ts +9 -9
- package/dist/targets/javascript/jquery/fixtures/nested.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/postdata-malformed.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/query-encoded.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/query.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/short.d.ts +5 -5
- package/dist/targets/javascript/jquery/fixtures/text-plain.d.ts +6 -6
- package/dist/targets/javascript/target.js +4 -4
- package/dist/targets/javascript/xhr/client.js +5 -5
- package/dist/targets/kotlin/okhttp/client.js +3 -3
- package/dist/targets/kotlin/target.js +4 -4
- package/dist/targets/node/axios/client.js +5 -5
- package/dist/targets/node/axios/fixtures/application-form-encoded.js +3 -2
- package/dist/targets/node/axios/fixtures/application-json.js +2 -1
- package/dist/targets/node/axios/fixtures/cookies.js +2 -1
- package/dist/targets/node/axios/fixtures/custom-method.js +2 -1
- package/dist/targets/node/axios/fixtures/full.js +3 -2
- package/dist/targets/node/axios/fixtures/headers.js +2 -1
- package/dist/targets/node/axios/fixtures/http-insecure.js +2 -1
- package/dist/targets/node/axios/fixtures/jsonObj-multiline.js +2 -1
- package/dist/targets/node/axios/fixtures/jsonObj-null-value.js +2 -1
- package/dist/targets/node/axios/fixtures/multipart-data.js +2 -1
- package/dist/targets/node/axios/fixtures/multipart-file.js +2 -1
- package/dist/targets/node/axios/fixtures/multipart-form-data-no-params.js +2 -1
- package/dist/targets/node/axios/fixtures/multipart-form-data.js +2 -1
- package/dist/targets/node/axios/fixtures/nested.js +2 -1
- package/dist/targets/node/axios/fixtures/postdata-malformed.js +2 -1
- package/dist/targets/node/axios/fixtures/query-encoded.js +2 -1
- package/dist/targets/node/axios/fixtures/query.js +2 -1
- package/dist/targets/node/axios/fixtures/short.js +2 -1
- package/dist/targets/node/axios/fixtures/text-plain.js +2 -1
- package/dist/targets/node/fetch/client.js +6 -6
- package/dist/targets/node/fetch/fixtures/application-form-encoded.js +2 -1
- package/dist/targets/node/fetch/fixtures/application-json.js +2 -1
- package/dist/targets/node/fetch/fixtures/cookies.js +2 -1
- package/dist/targets/node/fetch/fixtures/custom-method.js +2 -1
- package/dist/targets/node/fetch/fixtures/full.js +2 -1
- package/dist/targets/node/fetch/fixtures/headers.js +2 -1
- package/dist/targets/node/fetch/fixtures/http-insecure.js +2 -1
- package/dist/targets/node/fetch/fixtures/jsonObj-multiline.js +2 -1
- package/dist/targets/node/fetch/fixtures/jsonObj-null-value.js +2 -1
- package/dist/targets/node/fetch/fixtures/multipart-data.js +2 -1
- package/dist/targets/node/fetch/fixtures/multipart-file.js +2 -1
- package/dist/targets/node/fetch/fixtures/multipart-form-data-no-params.js +2 -1
- package/dist/targets/node/fetch/fixtures/multipart-form-data.js +2 -1
- package/dist/targets/node/fetch/fixtures/nested.js +2 -1
- package/dist/targets/node/fetch/fixtures/postdata-malformed.js +2 -1
- package/dist/targets/node/fetch/fixtures/query-encoded.js +2 -1
- package/dist/targets/node/fetch/fixtures/query.js +2 -1
- package/dist/targets/node/fetch/fixtures/short.js +2 -1
- package/dist/targets/node/fetch/fixtures/text-plain.js +2 -1
- package/dist/targets/node/native/client.js +10 -10
- package/dist/targets/node/request/client.js +7 -7
- package/dist/targets/node/target.js +5 -5
- package/dist/targets/node/unirest/client.js +10 -10
- package/dist/targets/objc/helpers.js +1 -1
- package/dist/targets/objc/nsurlsession/client.js +4 -4
- package/dist/targets/objc/target.js +4 -4
- package/dist/targets/ocaml/cohttp/client.js +3 -3
- package/dist/targets/ocaml/target.js +4 -4
- package/dist/targets/php/curl/client.js +12 -12
- package/dist/targets/php/guzzle/client.js +5 -5
- package/dist/targets/php/helpers.js +1 -1
- package/dist/targets/php/http1/client.js +3 -3
- package/dist/targets/php/http2/client.js +4 -4
- package/dist/targets/php/target.js +5 -5
- package/dist/targets/powershell/common.js +1 -1
- package/dist/targets/powershell/restmethod/client.js +3 -3
- package/dist/targets/powershell/target.js +4 -4
- package/dist/targets/powershell/webrequest/client.js +3 -3
- package/dist/targets/python/helpers.js +1 -1
- package/dist/targets/python/requests/client.js +3 -3
- package/dist/targets/python/target.js +5 -5
- package/dist/targets/r/httr/client.js +3 -3
- package/dist/targets/r/target.js +4 -4
- package/dist/targets/ruby/native/client.js +3 -3
- package/dist/targets/ruby/target.js +4 -4
- package/dist/targets/shell/curl/client.js +4 -4
- package/dist/targets/shell/httpie/client.js +4 -4
- package/dist/targets/shell/target.js +5 -5
- package/dist/targets/shell/wget/client.js +3 -3
- package/dist/targets/swift/helpers.js +1 -1
- package/dist/targets/swift/nsurlsession/client.js +4 -4
- package/dist/targets/swift/target.js +4 -4
- package/dist/targets/targets.js +4 -4
- package/package.json +14 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.kotlin = void 0;
|
|
4
4
|
var client_1 = require("./okhttp/client");
|
|
5
5
|
exports.kotlin = {
|
|
@@ -7,9 +7,9 @@ exports.kotlin = {
|
|
|
7
7
|
key: 'kotlin',
|
|
8
8
|
title: 'Kotlin',
|
|
9
9
|
extname: '.kt',
|
|
10
|
-
|
|
10
|
+
default: 'okhttp',
|
|
11
11
|
},
|
|
12
12
|
clientsById: {
|
|
13
|
-
okhttp: client_1.okhttp
|
|
14
|
-
}
|
|
13
|
+
okhttp: client_1.okhttp,
|
|
14
|
+
},
|
|
15
15
|
};
|
|
@@ -13,7 +13,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.axios = void 0;
|
|
18
18
|
var stringify_object_1 = __importDefault(require("stringify-object"));
|
|
19
19
|
var code_builder_1 = require("../../../helpers/code-builder");
|
|
@@ -22,7 +22,7 @@ exports.axios = {
|
|
|
22
22
|
key: 'axios',
|
|
23
23
|
title: 'Axios',
|
|
24
24
|
link: 'https://github.com/axios/axios',
|
|
25
|
-
description: 'Promise based HTTP client for the browser and node.js'
|
|
25
|
+
description: 'Promise based HTTP client for the browser and node.js',
|
|
26
26
|
},
|
|
27
27
|
convert: function (_a, options) {
|
|
28
28
|
var method = _a.method, fullUrl = _a.fullUrl, allHeaders = _a.allHeaders, postData = _a.postData;
|
|
@@ -31,7 +31,7 @@ exports.axios = {
|
|
|
31
31
|
push("const axios = require('axios');");
|
|
32
32
|
var reqOpts = {
|
|
33
33
|
method: method,
|
|
34
|
-
url: fullUrl
|
|
34
|
+
url: fullUrl,
|
|
35
35
|
};
|
|
36
36
|
if (Object.keys(allHeaders).length) {
|
|
37
37
|
reqOpts.headers = allHeaders;
|
|
@@ -62,7 +62,7 @@ exports.axios = {
|
|
|
62
62
|
reqOpts.data = postData.text;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
var stringifiedOptions = (0, stringify_object_1
|
|
65
|
+
var stringifiedOptions = (0, stringify_object_1.default)(reqOpts, { indent: ' ', inlineCharacterLimit: 80 });
|
|
66
66
|
push("const options = ".concat(stringifiedOptions, ";"));
|
|
67
67
|
blank();
|
|
68
68
|
push('axios');
|
|
@@ -74,5 +74,5 @@ exports.axios = {
|
|
|
74
74
|
push('console.error(error);', 2);
|
|
75
75
|
push('});', 1);
|
|
76
76
|
return join();
|
|
77
|
-
}
|
|
77
|
+
},
|
|
78
78
|
};
|
|
@@ -8,12 +8,13 @@ var options = {
|
|
|
8
8
|
method: 'POST',
|
|
9
9
|
url: 'https://httpbin.org/anything',
|
|
10
10
|
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
11
|
-
data: encodedParams
|
|
11
|
+
data: encodedParams,
|
|
12
12
|
};
|
|
13
13
|
axios
|
|
14
14
|
.request(options)
|
|
15
15
|
.then(function (response) {
|
|
16
16
|
console.log(response.data);
|
|
17
|
-
})
|
|
17
|
+
})
|
|
18
|
+
.catch(function (error) {
|
|
18
19
|
console.error(error);
|
|
19
20
|
});
|
|
@@ -11,12 +11,13 @@ var options = {
|
|
|
11
11
|
accept: 'application/json',
|
|
12
12
|
'content-type': 'application/x-www-form-urlencoded'
|
|
13
13
|
},
|
|
14
|
-
data: encodedParams
|
|
14
|
+
data: encodedParams,
|
|
15
15
|
};
|
|
16
16
|
axios
|
|
17
17
|
.request(options)
|
|
18
18
|
.then(function (response) {
|
|
19
19
|
console.log(response.data);
|
|
20
|
-
})
|
|
20
|
+
})
|
|
21
|
+
.catch(function (error) {
|
|
21
22
|
console.error(error);
|
|
22
23
|
});
|
|
@@ -13,7 +13,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.fetch = void 0;
|
|
18
18
|
var stringify_object_1 = __importDefault(require("stringify-object"));
|
|
19
19
|
var code_builder_1 = require("../../../helpers/code-builder");
|
|
@@ -23,7 +23,7 @@ exports.fetch = {
|
|
|
23
23
|
key: 'fetch',
|
|
24
24
|
title: 'Fetch',
|
|
25
25
|
link: 'https://github.com/bitinn/node-fetch',
|
|
26
|
-
description: 'Simplified HTTP node-fetch client'
|
|
26
|
+
description: 'Simplified HTTP node-fetch client',
|
|
27
27
|
},
|
|
28
28
|
convert: function (_a, options) {
|
|
29
29
|
var _b;
|
|
@@ -34,7 +34,7 @@ exports.fetch = {
|
|
|
34
34
|
push("const fetch = require('node-fetch');");
|
|
35
35
|
var url = fullUrl;
|
|
36
36
|
var reqOpts = {
|
|
37
|
-
method: method
|
|
37
|
+
method: method,
|
|
38
38
|
};
|
|
39
39
|
if (Object.keys(headersObj).length) {
|
|
40
40
|
reqOpts.headers = headersObj;
|
|
@@ -107,7 +107,7 @@ exports.fetch = {
|
|
|
107
107
|
if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
|
|
108
108
|
delete reqOpts.headers;
|
|
109
109
|
}
|
|
110
|
-
var stringifiedOptions = (0, stringify_object_1
|
|
110
|
+
var stringifiedOptions = (0, stringify_object_1.default)(reqOpts, {
|
|
111
111
|
indent: ' ',
|
|
112
112
|
inlineCharacterLimit: 80,
|
|
113
113
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
|
|
@@ -118,7 +118,7 @@ exports.fetch = {
|
|
|
118
118
|
return "JSON.stringify(".concat(originalResult, ")");
|
|
119
119
|
}
|
|
120
120
|
return originalResult;
|
|
121
|
-
}
|
|
121
|
+
},
|
|
122
122
|
});
|
|
123
123
|
push("const options = ".concat(stringifiedOptions, ";"));
|
|
124
124
|
blank();
|
|
@@ -136,5 +136,5 @@ exports.fetch = {
|
|
|
136
136
|
return join()
|
|
137
137
|
.replace(/'encodedParams'/, 'encodedParams')
|
|
138
138
|
.replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
|
|
139
|
-
}
|
|
139
|
+
},
|
|
140
140
|
};
|
|
@@ -12,4 +12,5 @@ var options = {
|
|
|
12
12
|
};
|
|
13
13
|
fetch(url, options)
|
|
14
14
|
.then(function (res) { return res.json(); })
|
|
15
|
-
.then(function (json) { return console.log(json); })
|
|
15
|
+
.then(function (json) { return console.log(json); })
|
|
16
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -15,4 +15,5 @@ var options = {
|
|
|
15
15
|
};
|
|
16
16
|
fetch(url, options)
|
|
17
17
|
.then(function (res) { return res.json(); })
|
|
18
|
-
.then(function (json) { return console.log(json); })
|
|
18
|
+
.then(function (json) { return console.log(json); })
|
|
19
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/cookies';
|
|
|
4
4
|
var options = { method: 'GET', headers: { cookie: 'foo=bar; bar=baz' } };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/anything';
|
|
|
4
4
|
var options = { method: 'PROPFIND' };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -15,4 +15,5 @@ var options = {
|
|
|
15
15
|
};
|
|
16
16
|
fetch(url, options)
|
|
17
17
|
.then(function (res) { return res.json(); })
|
|
18
|
-
.then(function (json) { return console.log(json); })
|
|
18
|
+
.then(function (json) { return console.log(json); })
|
|
19
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -7,4 +7,5 @@ var options = {
|
|
|
7
7
|
};
|
|
8
8
|
fetch(url, options)
|
|
9
9
|
.then(function (res) { return res.json(); })
|
|
10
|
-
.then(function (json) { return console.log(json); })
|
|
10
|
+
.then(function (json) { return console.log(json); })
|
|
11
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'http://httpbin.org/anything';
|
|
|
4
4
|
var options = { method: 'GET' };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -8,4 +8,5 @@ var options = {
|
|
|
8
8
|
};
|
|
9
9
|
fetch(url, options)
|
|
10
10
|
.then(function (res) { return res.json(); })
|
|
11
|
-
.then(function (json) { return console.log(json); })
|
|
11
|
+
.then(function (json) { return console.log(json); })
|
|
12
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -8,4 +8,5 @@ var options = {
|
|
|
8
8
|
};
|
|
9
9
|
fetch(url, options)
|
|
10
10
|
.then(function (res) { return res.json(); })
|
|
11
|
-
.then(function (json) { return console.log(json); })
|
|
11
|
+
.then(function (json) { return console.log(json); })
|
|
12
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -10,4 +10,5 @@ var options = { method: 'POST' };
|
|
|
10
10
|
options.body = formData;
|
|
11
11
|
fetch(url, options)
|
|
12
12
|
.then(function (res) { return res.json(); })
|
|
13
|
-
.then(function (json) { return console.log(json); })
|
|
13
|
+
.then(function (json) { return console.log(json); })
|
|
14
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -9,4 +9,5 @@ var options = { method: 'POST' };
|
|
|
9
9
|
options.body = formData;
|
|
10
10
|
fetch(url, options)
|
|
11
11
|
.then(function (res) { return res.json(); })
|
|
12
|
-
.then(function (json) { return console.log(json); })
|
|
12
|
+
.then(function (json) { return console.log(json); })
|
|
13
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/anything';
|
|
|
4
4
|
var options = { method: 'POST', headers: { 'Content-Type': 'multipart/form-data' } };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -8,4 +8,5 @@ var options = { method: 'POST' };
|
|
|
8
8
|
options.body = formData;
|
|
9
9
|
fetch(url, options)
|
|
10
10
|
.then(function (res) { return res.json(); })
|
|
11
|
-
.then(function (json) { return console.log(json); })
|
|
11
|
+
.then(function (json) { return console.log(json); })
|
|
12
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/anything?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value
|
|
|
4
4
|
var options = { method: 'GET' };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/anything';
|
|
|
4
4
|
var options = { method: 'POST', headers: { 'content-type': 'application/json' } };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/anything?startTime=2019-06-13T19%3A08%3A25.455Z&e
|
|
|
4
4
|
var options = { method: 'GET' };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value';
|
|
|
4
4
|
var options = { method: 'GET' };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/anything';
|
|
|
4
4
|
var options = { method: 'GET' };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -4,4 +4,5 @@ var url = 'https://httpbin.org/anything';
|
|
|
4
4
|
var options = { method: 'POST', headers: { 'content-type': 'text/plain' }, body: 'Hello World' };
|
|
5
5
|
fetch(url, options)
|
|
6
6
|
.then(function (res) { return res.json(); })
|
|
7
|
-
.then(function (json) { return console.log(json); })
|
|
7
|
+
.then(function (json) { return console.log(json); })
|
|
8
|
+
.catch(function (err) { return console.error('error:' + err); });
|
|
@@ -13,7 +13,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.native = void 0;
|
|
18
18
|
var stringify_object_1 = __importDefault(require("stringify-object"));
|
|
19
19
|
var code_builder_1 = require("../../../helpers/code-builder");
|
|
@@ -22,7 +22,7 @@ exports.native = {
|
|
|
22
22
|
key: 'native',
|
|
23
23
|
title: 'HTTP',
|
|
24
24
|
link: 'http://nodejs.org/api/http.html#http_http_request_options_callback',
|
|
25
|
-
description: 'Node.js native HTTP interface'
|
|
25
|
+
description: 'Node.js native HTTP interface',
|
|
26
26
|
},
|
|
27
27
|
convert: function (_a, options) {
|
|
28
28
|
var _b;
|
|
@@ -34,11 +34,11 @@ exports.native = {
|
|
|
34
34
|
hostname: uriObj.hostname,
|
|
35
35
|
port: uriObj.port,
|
|
36
36
|
path: uriObj.path,
|
|
37
|
-
headers: allHeaders
|
|
37
|
+
headers: allHeaders,
|
|
38
38
|
};
|
|
39
39
|
push("const http = require('".concat((_b = uriObj.protocol) === null || _b === void 0 ? void 0 : _b.replace(':', ''), "');"));
|
|
40
40
|
blank();
|
|
41
|
-
push("const options = ".concat((0, stringify_object_1
|
|
41
|
+
push("const options = ".concat((0, stringify_object_1.default)(reqOpts, { indent: opts.indent }), ";"));
|
|
42
42
|
blank();
|
|
43
43
|
push('const req = http.request(options, function (res) {');
|
|
44
44
|
push('const chunks = [];', 1);
|
|
@@ -57,26 +57,26 @@ exports.native = {
|
|
|
57
57
|
case 'application/x-www-form-urlencoded':
|
|
58
58
|
if (postData.paramsObj) {
|
|
59
59
|
unshift("const qs = require('querystring');");
|
|
60
|
-
push("req.write(qs.stringify(".concat((0, stringify_object_1
|
|
60
|
+
push("req.write(qs.stringify(".concat((0, stringify_object_1.default)(postData.paramsObj, {
|
|
61
61
|
indent: ' ',
|
|
62
|
-
inlineCharacterLimit: 80
|
|
62
|
+
inlineCharacterLimit: 80,
|
|
63
63
|
}), "));"));
|
|
64
64
|
}
|
|
65
65
|
break;
|
|
66
66
|
case 'application/json':
|
|
67
67
|
if (postData.jsonObj) {
|
|
68
|
-
push("req.write(JSON.stringify(".concat((0, stringify_object_1
|
|
68
|
+
push("req.write(JSON.stringify(".concat((0, stringify_object_1.default)(postData.jsonObj, {
|
|
69
69
|
indent: ' ',
|
|
70
|
-
inlineCharacterLimit: 80
|
|
70
|
+
inlineCharacterLimit: 80,
|
|
71
71
|
}), "));"));
|
|
72
72
|
}
|
|
73
73
|
break;
|
|
74
74
|
default:
|
|
75
75
|
if (postData.text) {
|
|
76
|
-
push("req.write(".concat((0, stringify_object_1
|
|
76
|
+
push("req.write(".concat((0, stringify_object_1.default)(postData.text, { indent: opts.indent }), ");"));
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
push('req.end();');
|
|
80
80
|
return join();
|
|
81
|
-
}
|
|
81
|
+
},
|
|
82
82
|
};
|
|
@@ -13,7 +13,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.request = void 0;
|
|
18
18
|
var stringify_object_1 = __importDefault(require("stringify-object"));
|
|
19
19
|
var code_builder_1 = require("../../../helpers/code-builder");
|
|
@@ -22,7 +22,7 @@ exports.request = {
|
|
|
22
22
|
key: 'request',
|
|
23
23
|
title: 'Request',
|
|
24
24
|
link: 'https://github.com/request/request',
|
|
25
|
-
description: 'Simplified HTTP request client'
|
|
25
|
+
description: 'Simplified HTTP request client',
|
|
26
26
|
},
|
|
27
27
|
convert: function (_a, options) {
|
|
28
28
|
var method = _a.method, url = _a.url, fullUrl = _a.fullUrl, postData = _a.postData, headersObj = _a.headersObj, cookies = _a.cookies;
|
|
@@ -33,7 +33,7 @@ exports.request = {
|
|
|
33
33
|
blank();
|
|
34
34
|
var reqOpts = {
|
|
35
35
|
method: method,
|
|
36
|
-
url: fullUrl
|
|
36
|
+
url: fullUrl,
|
|
37
37
|
};
|
|
38
38
|
if (Object.keys(headersObj).length) {
|
|
39
39
|
reqOpts.headers = headersObj;
|
|
@@ -65,8 +65,8 @@ exports.request = {
|
|
|
65
65
|
value: "fs.createReadStream(".concat(param.fileName, ")"),
|
|
66
66
|
options: {
|
|
67
67
|
filename: param.fileName,
|
|
68
|
-
contentType: param.contentType ? param.contentType : null
|
|
69
|
-
}
|
|
68
|
+
contentType: param.contentType ? param.contentType : null,
|
|
69
|
+
},
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
else if (param.value) {
|
|
@@ -95,7 +95,7 @@ exports.request = {
|
|
|
95
95
|
if (includeFS) {
|
|
96
96
|
unshift("const fs = require('fs');");
|
|
97
97
|
}
|
|
98
|
-
push("const options = ".concat((0, stringify_object_1
|
|
98
|
+
push("const options = ".concat((0, stringify_object_1.default)(reqOpts, { indent: ' ', inlineCharacterLimit: 80 }), ";"));
|
|
99
99
|
blank();
|
|
100
100
|
push('request(options, function (error, response, body) {');
|
|
101
101
|
push('if (error) throw new Error(error);', 1);
|
|
@@ -103,5 +103,5 @@ exports.request = {
|
|
|
103
103
|
push('console.log(body);', 1);
|
|
104
104
|
push('});');
|
|
105
105
|
return join();
|
|
106
|
-
}
|
|
106
|
+
},
|
|
107
107
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.node = void 0;
|
|
4
4
|
var client_1 = require("./axios/client");
|
|
5
5
|
var client_2 = require("./fetch/client");
|
|
@@ -11,14 +11,14 @@ exports.node = {
|
|
|
11
11
|
key: 'node',
|
|
12
12
|
title: 'Node.js',
|
|
13
13
|
extname: '.js',
|
|
14
|
-
|
|
15
|
-
cli: 'node %s'
|
|
14
|
+
default: 'native',
|
|
15
|
+
cli: 'node %s',
|
|
16
16
|
},
|
|
17
17
|
clientsById: {
|
|
18
18
|
native: client_3.native,
|
|
19
19
|
request: client_4.request,
|
|
20
20
|
unirest: client_5.unirest,
|
|
21
21
|
axios: client_1.axios,
|
|
22
|
-
fetch: client_2.fetch
|
|
23
|
-
}
|
|
22
|
+
fetch: client_2.fetch,
|
|
23
|
+
},
|
|
24
24
|
};
|