I want to start using axios to get data from a restful api I have already coded, but I keep on recieving [object Promise] instead of something useful like data.
Here is my code.
import axios from "axios";
const get = url => {
return axios
.get(url)
.then(response => {
return response.data;
})
.catch(error => {
return error;
});
};
I console.log the return value of this and get [object Promise]. I need the data my restful api is sending back when I call get in the code below.
const {get, post} = client;
const data = get("localhost:4000/data");
console.log(`Data: ${data}`);
Any help is appreciated.