-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (51 loc) · 2.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const https = require('https');
const chalk = require('chalk')
const yargs = require('yargs')
const readline = require("readline");
const fs = require('fs');
// Customerie yargs verison
yargs.version('1.1.0')
// Config readline
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// HTTP requests
rl.question('What is your name? ', function (name) {
rl.question(`What would you like to do today: (GET/POST/PUT/DELETE)`, function (method) {
if (method === "GET") {
rl.question('What is the request url? ', function (url) {
const output = https.get(`${url}`)
const writeStream = fs.writeFileSync('output/get_output.txt', JSON.stringify(output));
})
} else if (method === "POST") {
rl.question('What is the request url? ', function (url) {
rl.question('Paste the json body here: ', function (data) {
console.log(chalk.green('Request Success!'));
const output = https.post(`${url}`, data)
if (err) {
console.log(chalk.red('Error!!'));
}
})
})
} else if (method === 'PUT') {
rl.question('What is the request url? ', function (url) {
rl.question('Paste the json body here: ', function (data) {
console.log(chalk.green('Request Success!'));
const output = https.put(`${url}`, data)
if (err) {
console.log(chalk.red('Error!!'));
}
})
})
} else if (method === 'DELETE') {
rl.question('What is the request url? ', function (url) {
const output = https.put(`${url}`)
console.log(chalk.delete('Request Success!'));
if (err) {
console.log(chalk.red('Error!!'));
}
})
}
})
})