Browse Source

add api calls and start editing format 🔧

main
Skinkane 5 years ago
parent
commit
4da2c3b483
  1. 41
      index.js

41
index.js

@ -4,29 +4,46 @@ import axios from 'axios';
const app = fastify({ logger: true });
app.get('/', async (req, res) => {
return {
catfacts: getCatFacts(),
foxes: getFoxDay(),
day: getDayOfCountry()
};
return getAll();
});
const getCatFacts = async(id) =>{
axios.get('https://cat-fact.herokuapp.com/facts/{id}').then(res => {});
const getCatFacts = () =>{
let facts = [];
return new Promise(resolve => {axios.get('https://cat-fact.herokuapp.com/facts').then(res => {
let facts = [];
let i = 0;
while (i < 3) {
facts.push(res.data[i].text);
i++;
};
resolve(facts);
});});
};
const getFoxDay = () =>{
return new Promise(resolve => {
axios.get('https://randomfox.ca/floof/').then(res => {resolve(res.data.image)});
});
};
const getFoxDay = async(id) =>{
axios.get('https://randomfox.ca/floof/').then(res => {});
const getDayOfCountry = () => {
return new Promise(resolve => {
axios.get('https://date.nager.at/api/v2/publicholidays/2019/FR').then(res => {resolve(res.data)});
});
};
const getDayOfCountry = async(id) =>{
axios.get('https://randomfox.ca/floof/').then(res => {});
const getAll = () => {
let promises = Promise.all([getCatFacts(),getFoxDay(),getDayOfCountry()]);
console.log([promises[1]]);
let data = promises
return data;
};
const start = async () => {
try {
await app.listen(5000);
getCatFacts(1);
} catch (err) {
app.log.error(err);
process.exit(1);

Loading…
Cancel
Save