Browse Source

Création API

Création d'une API regroupant 3 API,
Une api permet d'avoir des "fun fact" sur les chats
Une api permettant d'avoir une image de renard
Une api permettant d'avoir les jours feriés (par pays)
main
Adrien-Ba 4 years ago
parent
commit
5c6fdab328
  1. 51
      index.js
  2. 3893
      package-lock.json

51
index.js

@ -6,9 +6,9 @@ const app = fastify({ logger: true });
app.post('/', async (req, res) => {
return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
"foxPicture": await getFox(),
"catFacts": await getChat(),
"holidays": await getHolidays(req.body?.countryCode ?? "FR"),
};
});
@ -25,3 +25,48 @@ const start = async () => {
}
};
start();
//REQUETES
async function getChat() {
try {
return await axios.get('https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=3').then(
function(response) {
return response.data.map(element => element.text)
}
)
} catch (error) {
console.error(error);
return null;
}
}
async function getFox() {
try {
return await axios.get('https://randomfox.ca/floof/').then(
function(response) {
return response.data.link
}
)
} catch (error) {
console.error(error);
return null;
}
}
async function getHolidays(country) {
try {
return await axios.get('https://date.nager.at/api/v3/publicholidays/2022/' + country).then(
function(response) {
return response.data
}
)
} catch (error) {
console.error(error);
return null;
}
}

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

Loading…
Cancel
Save