-
-
Notifications
You must be signed in to change notification settings - Fork 615
Closed
Labels
enhancementNew feature or requestNew feature or requestopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch library
Description
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
- I’m willing to open a PR (see CONTRIBUTING.md)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch library