From 7df9edb966f2cd3bc62c9b9699a7a1e3b6618bac Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 15 Feb 2021 17:33:18 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20fow=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 91e7f05..d214261 100644 --- a/index.js +++ b/index.js @@ -4,16 +4,6 @@ import axios from 'axios'; 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() { const response = await axios.get("https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3"); const data = await response.data; @@ -21,11 +11,19 @@ async function getCat() { 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) => { const catInfos = await getCat(); + const foxImage = await getFox(); return { message: `Welcome to Node Babel`, - catFacts: catInfos + catFacts: catInfos, + fox: foxImage, }; });