-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHAPIBook.js
96 lines (83 loc) · 2.91 KB
/
HAPIBook.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸 🗸
const axios = require("axios");
function getBookByName(name) {
name = name.replace(/\s/g, "+");
const options = {
method: 'GET',
url: 'https://hapi-books.p.rapidapi.com/search/' + name,
headers: {
'X-RapidAPI-Key': 'ff5169b2c0mshc86c10e8c1fce75p1e987ajsn2a66931edc3b',
'X-RapidAPI-Host': 'hapi-books.p.rapidapi.com'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
}
function getPopularBooksByYear(year) {
const options = {
method: 'GET',
url: 'https://hapi-books.p.rapidapi.com/top/' + year,
headers: {
'X-RapidAPI-Key': 'ff5169b2c0mshc86c10e8c1fce75p1e987ajsn2a66931edc3b',
'X-RapidAPI-Host': 'hapi-books.p.rapidapi.com'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
}
function getBookByGenreAndYear(genre, year) {
const options = {
method: 'GET',
url: 'https://hapi-books.p.rapidapi.com/nominees/' + genre + '/' + year,
headers: {
'X-RapidAPI-Key': 'ff5169b2c0mshc86c10e8c1fce75p1e987ajsn2a66931edc3b',
'X-RapidAPI-Host': 'hapi-books.p.rapidapi.com'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
}
function getWeeklyPopularBookByGenre(genre) {
const options = {
method: 'GET',
url: 'https://hapi-books.p.rapidapi.com/month/2022/3',
headers: {
'X-RapidAPI-Key': 'ff5169b2c0mshc86c10e8c1fce75p1e987ajsn2a66931edc3b',
'X-RapidAPI-Host': 'hapi-books.p.rapidapi.com'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
}
function getFefteenPopularBookInAMounthOfAYear(mounth, year) {
const options = {
method: 'GET',
url: 'https://hapi-books.p.rapidapi.com/month/' + year + '/' + mounth,
headers: {
'X-RapidAPI-Key': 'ff5169b2c0mshc86c10e8c1fce75p1e987ajsn2a66931edc3b',
'X-RapidAPI-Host': 'hapi-books.p.rapidapi.com'
}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
}
// getBookByName("Harry Potter");
// getPopularBooksByYear("2020");
//getBookByGenreAndYear("romance","2020");
//getWeeklyPopularBookByGenre("romance");
//getFefteenPopularBookInAMounthOfAYear("3", "2022");