0

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

Mahesh
  • 1,117
  • 2
  • 23
  • 42

1 Answers1

2

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()
P.E. Joëssel
  • 1,393
  • 10
  • 18