Browse Source

api ok

main
SimonBurdy 4 years ago
parent
commit
bb10cafa27
  1. 27
      index.js
  2. 13548
      package-lock.json
  3. 1
      package.json
  4. 7150
      yarn.lock

27
index.js

@ -4,13 +4,30 @@ import axios from 'axios';
const app = fastify({ logger: true });
app.post('/', async (req, res) => {
const getFoxImg = () => axios.get('https://randomfox.ca/floof/').then(resp => resp.data.image).catch(() => null);
const getCatFacts = (nb) => axios.get( `https://cat-fact.herokuapp.com/facts/random?animal_type=cat&amount=${nb}`).then(resp => resp.data.map(catInfo => catInfo.text)).catch(() => null );
const getHolidays = (year , contryCode) => axios.get( `https://date.nager.at/api/v3/publicholidays/${year}/${contryCode}`).then(resp => resp.data).catch(() => null);
app.post('/' , async (req, res) => {
let imgFox = await getFoxImg();
let catFacts = await getCatFacts(3);
let holidays = await getHolidays(2022 ,req.body.countryCode);
return {
message: `Welcome to Node Babel with ${
req.body?.testValue ?? 'no testValue'
}`,
imgFox,
catFacts,
holidays
};
});
})
// Only used for dev server, do not remove
app.head('/', () => ({ ping: 'pong' }));

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

1
package.json

@ -14,6 +14,7 @@
"axios": "^0.21.1",
"fastify": "^3.12.0",
"nodemon": "^2.0.7",
"npm": "^8.5.0",
"zod": "^3.11.6"
},
"devDependencies": {

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

Loading…
Cancel
Save