Browse Source

feat(index.js) merge list of api

main
sipe-daniel 5 years ago
parent
commit
d47ab58f4b
  1. 41
      index.js
  2. 3029
      package-lock.json

41
index.js

@ -4,12 +4,43 @@ import axios from 'axios';
const app = fastify({ logger: true });
app.get('/', async (req, res) => {
return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
};
let catFacts = [];
let foxPicture;
let holidays;
await axios.get("https://catfact.ninja/facts?limit=3")
.then(function(response){
response.data.data.forEach(fillCatFact);
function fillCatFact(elt, item) {
catFacts[item] = elt.fact;
}
}).catch(function(error){
catFacts = null;
console.log(error);
});
await axios.get('https://randomfox.ca/floof/')
.then(function (response) {
foxPicture = response.data.image;
})
.catch(function (error) {
foxPicture = null;
console.log(error);
})
await axios.get(`https://date.nager.at/api/v2/publicholidays/2021/${req.params.countryCode ? req.params.countryCode : 'FR'}`)
.then(function (response) {
holidays = response.data;
})
.catch(function (error) {
holidays = null;
console.log(error);
})
let data = { foxPicture: foxPicture, catFacts: catFacts, holidays: holidays };
res.status(200).send(JSON.stringify(data));
});
// Run the server!

3029
package-lock.json
File diff suppressed because it is too large
View File

Loading…
Cancel
Save