I'm now trying to make get/post api request with axios javascript.But the problem is that my Api get function return the result before it receives data from server.here is my code
function Api(base_url) {
this.base_url = base_url;
}
Api.prototype = {
constructor: Api,
get: function (route) {
var url = this.base_url + route;
axios.get(url)
.then(
response => {
console.log(response.data.data);
return response.data.data;
})
return "hello";
},
post: function (route) {
}
}
And I call get function like this
api = new Api("http://localhost:8080/");
var data = api.get("post/get");
console.log(data);
Instead of waiting for reply from server,my function return "hello" as return data.Can someone help me why and how to solve this please?