-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprint.js
50 lines (41 loc) · 1.47 KB
/
print.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
const chalk = require('chalk');
const log = (str) => {
console.log(`${chalk.yellow('INFO:')} ${str}`)
}
function print_getBooksByQueryString(res) {
console.log(chalk.yellow('----'));
log(chalk.blue('executing "getBooksByQueryString"...'));
log(chalk.white('Successfully got some data!'))
log(chalk.green(
JSON.stringify(res.data, null, 2)
));
const requestUrl = res.config.baseURL + res.request.path;
log(chalk.white('Request URL used -> ') + chalk.magenta(`"${requestUrl}"`))
console.log(chalk.yellow('----'));
}
function print_getBooksByUrlPath(res) {
console.log(chalk.yellow('----'));
log(chalk.blue('executing "getBooksByQueryString"...'));
log(chalk.white('Successfully got some data!'))
log(chalk.green(
JSON.stringify(res.data, null, 2)
));
log(chalk.white('Request URL used -> ') + chalk.magenta(`"${res.config.url}"`))
console.log(chalk.yellow('----'));
}
function print_getBooksByMediaType(res) {
console.log(chalk.yellow('----'));
log(chalk.blue('executing "getBooksByMediaType"...'));
log(chalk.white('Successfully got some data!'))
log(chalk.green(
JSON.stringify(res.data, null, 2)
));
const acceptHeader = res.config.headers["Accept"];
log(chalk.white('Accept Header used -> ') + chalk.magenta(`"${acceptHeader}"`))
console.log(chalk.yellow('----'));
}
module.exports = {
print_getBooksByQueryString,
print_getBooksByMediaType,
print_getBooksByUrlPath
}