Browse Source

fow image

main
Pierre 5 years ago
parent
commit
7df9edb966
  1. 20
      index.js

20
index.js

@ -4,16 +4,6 @@ import axios from 'axios';
const app = fastify({ logger: true }); const app = fastify({ logger: true });
function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// const getCat = async () => {
// console.log('toto');
// let response = await axios.get(`https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3`)
// .then(res => response.json());
// };
async function getCat() { async function getCat() {
const response = await axios.get("https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3"); const response = await axios.get("https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3");
const data = await response.data; const data = await response.data;
@ -21,11 +11,19 @@ async function getCat() {
return text; return text;
} }
async function getFox() {
const response = await axios.get("https://randomfox.ca/floof/");
const image = await response.data.image;
return image;
}
app.post('/', async (req, res) => { app.post('/', async (req, res) => {
const catInfos = await getCat(); const catInfos = await getCat();
const foxImage = await getFox();
return { return {
message: `Welcome to Node Babel`, message: `Welcome to Node Babel`,
catFacts: catInfos
catFacts: catInfos,
fox: foxImage,
}; };
}); });

Loading…
Cancel
Save