julien dudek 5 years ago
parent
commit
a29aa5e489
  1. 43
      index.js
  2. 3018
      package-lock.json
  3. 4220
      yarn.lock

43
index.js

@ -3,15 +3,50 @@ import fastify from 'fastify';
import axios from 'axios'; import axios from 'axios';
const app = fastify({ logger: true }); const app = fastify({ logger: true });
const URLHOLIDAYS = `https://date.nager.at/api/v2/PublicHolidays/2021/`;
const URLANIMALS= `https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3`
const URLFOX = `https://randomfox.ca/floof/`;
app.get('/', async (req, res) => {
const getCatFacts = async () => {
try{
const response = await axios.get(URLANIMALS);
const json = await response.data.map(cats=>cats.text);
return json;
}catch(err){
console.log(err);
return null;
}Ò
};
const getFox = async()=>{
try{
const response = await axios.get(URLFOX);
const json = await response.data.image;
return json;
}catch(err){
console.log(err);
return null;
}
}
const getHolidays = async(country)=>{
try{
const response = await axios.get(`${URLHOLIDAYS}${country}`);
const data = await response.data;
return data;
}catch(err){
console.error(err);
return null;
}
}
app.post('/', async (req, res) => {
const [catFacts,foxPicture,holidays]= await Promise.all([getCatFacts(),getFox(),getHolidays(req.body.countryCode??'')])
return { return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
foxPicture,catFacts,holidays,
}; };
}); });
// Run the server! // Run the server!
const start = async () => { const start = async () => {
try { try {

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

4220
yarn.lock
File diff suppressed because it is too large
View File

Loading…
Cancel
Save