but when i go on the that link there's json data.
import axios from "axios";
exports.handler = async function (event, context) {
let results;
const fetchData = async () => {
axios.get("https://randomuser.me/api").then((res) => {
console.log(res);
});
// conlog.log(results.data);
};
return {
statusCode: 200,
body: JSON.stringify(fetchData()),
};
};
here's my code i tried to read this with python requests and it worded fine.
i even tried
import axios from "axios";
exports.handler = async function (event, context) {
return {
statusCode: 200,
body: JSON.stringify(axios.get("https://randomuser.me/api")),
};
};
but it still returns an {}. can someone please tell me what am doing wrong here.
Edit:
i at first had this:
import axios from "axios";
exports.handler = async function (event, context) {
let results;
const fetchData = async () => {
results = await axios.get("https://randomuser.me/api");
conlog.log(results.data);
return results.data;
};
return {
statusCode: 200,
body: JSON.stringify(fetchData()),
};
};
Edit 2:
i Have this code below as part of my app.js and it works just fine.
const fetchData = async () => {
const results = await axios.get("/.netlify/functions/print");
console.log(results);
};
useEffect(() => {
fetchData();
}, []);