Reputation: 1333
I am using the following snippet to hit an API and get its response. I want to know how much time it took to fetch the data
const fetch_table_data = async () => { const response = await axios.get(`URL_HERE`, {headers : {'Authorization': 'Token abc'}});if (response.status === 200){
// what is the time taken to fetch this data??? <-------------------
}}
fetch_table_data()
Please suggest a workaround. Thanks
Upvotes: 0
Views: 2142
Reputation: 1443
You can use the native Performance interface.
const fetch_table_data = async () => {
const request_start_at = performance.now();
const response = await axios.get(`URL_HERE`, {
headers : {
'Authorization': 'Token abc'
}
});
const request_end_at = performance.now();
const request_duration = request_ent_at - request_start_at;
if (response.status === 200) {
console.log(duration);
}
}
fetch_table_data()
Upvotes: 2