Description
I'm looking to use middleware to measure the request time of openapi-fetch client requests - what's a good way to achieve this? The objects available in openapi-fetch middleware don't appear to include request time.
One approach I've considered is attaching the request start time to the Request object when onRequest is triggered, and then calculating the request time in the onResponse hook e.g.
const myMiddleware: Middleware = {
async onRequest({ request }) {
// @ts-ignore
request.startTime = performance.now();
},
async onResponse({ request }) {
const endTime = performance.now();
// @ts-ignore
const latency = endTime - request.startTime;
console.log(latency);
},
};
This requires working around the types somewhat though.
Are there any other approaches I could consider?
Proposal
N/A
Extra
Description
I'm looking to use middleware to measure the request time of
openapi-fetchclient requests - what's a good way to achieve this? The objects available inopenapi-fetchmiddleware don't appear to include request time.One approach I've considered is attaching the request start time to the
Requestobject whenonRequestis triggered, and then calculating the request time in theonResponsehook e.g.This requires working around the types somewhat though.
Are there any other approaches I could consider?
Proposal
N/A
Extra