Browse Source

: add API fetch

main
Jean-François GAUTREAU 5 years ago
parent
commit
ae28db576b
  1. 26
      index.js
  2. 2920
      package-lock.json
  3. 3
      package.json
  4. 5
      yarn.lock

26
index.js

@ -1,8 +1,27 @@
import fastify from 'fastify'; import fastify from 'fastify';
import axios from "axios";
// see axios doc on how to use it // see axios doc on how to use it
import axios from 'axios';
const app = fastify({ logger: true });
const app = fastify({logger: true});
const getCatFacts = async () => {
const url ='https://cat-fact.herokuapp.com/facts/random?amount=3';
const {data} = await axios.get(url);
data.forEach( d => console.log(d.text));
};
const getFoxImage = async () => {
const url ='https://randomfox.ca/floof/';
const {data} = await axios.get(url);
console.log(data.image);
};
const getCountryHour = async () => {
const url ='https://date.nager.at/api/v2/publicholidays/2021/CU';
const {data} = await axios.get(url);
data.forEach( d => console.log(d.date));
};
app.get('/', async (req, res) => { app.get('/', async (req, res) => {
return { return {
@ -22,3 +41,6 @@ const start = async () => {
} }
}; };
start(); start();
getCatFacts();
getFoxImage();
getCountryHour();

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

3
package.json

@ -13,7 +13,8 @@
"@babel/preset-stage-3": "^7.8.3", "@babel/preset-stage-3": "^7.8.3",
"axios": "^0.21.1", "axios": "^0.21.1",
"fastify": "^3.12.0", "fastify": "^3.12.0",
"nodemon": "^2.0.7"
"nodemon": "^2.0.7",
"yarn": "^1.22.10"
}, },
"devDependencies": { "devDependencies": {
"husky": "5.0.9", "husky": "5.0.9",

5
yarn.lock

@ -2645,3 +2645,8 @@ yallist@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==
yarn@^1.22.10:
version "1.22.10"
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.10.tgz#c99daa06257c80f8fa2c3f1490724e394c26b18c"
integrity sha512-IanQGI9RRPAN87VGTF7zs2uxkSyQSrSPsju0COgbsKQOOXr5LtcVPeyXWgwVa0ywG3d8dg6kSYKGBuYK021qeA==
Loading…
Cancel
Save