Skip to content

Instantly share code, notes, and snippets.

@samrobbins85
Created July 31, 2020 16:20
Show Gist options
  • Save samrobbins85/8737b05f8b0ee11be6de026aad1d7b54 to your computer and use it in GitHub Desktop.
Save samrobbins85/8737b05f8b0ee11be6de026aad1d7b54 to your computer and use it in GitHub Desktop.
Timing for axios requests
const axiosTiming = (instance) => {
instance.interceptors.request.use((request) => {
request.ts = Date.now();
return request;
});
instance.interceptors.response.use((response) => {
const timeInMs = `${Number(Date.now() - response.config.ts).toFixed()}ms`;
response.latency = timeInMs;
return response;
});
};
axiosTiming(axios);
// Then whatever you call the response.latency will be the latency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment