-
-
Notifications
You must be signed in to change notification settings - Fork 624
Open
Labels
enhancementNew feature or requestNew feature or requestopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch library
Description
Description
Example use case: A middleware that adds a configurable timeout, like this: #2527 (comment)
// Timeout middleware
fetchClient.use({
async onRequest({ request, params: { timeout } }) {
const signal =
timeout === Infinity ?
request.signal
: AbortSignal.any([
request.signal,
AbortSignal.timeout(typeof timeout === 'number' && timeout >= 0 ? timeout : REQUEST_TIMEOUT),
]);
return new Request(request, { signal });
},
});Since #2527, the MiddlewareRequestParams are easily augmentable:
declare module 'openapi-fetch' {
interface MiddlewareRequestParams {
timeout?: number;
}
}so maybe, ParamsOption should somehow do the same.
Proposal
Ergonomically, I'd like to send my request like this
client['/api/takes-a-while'].PUT({ params: { timeout: 120_000 } })and use the timeout custom param in my middleware, without type assertions or disabling TypeScript for this line.
Alternatively, I could also imagine a custom meta option, like TanStack Query does it: https://tanstack.com/query/latest/docs/framework/react/typescript#typing-meta
client['/api/takes-a-while'].PUT({ meta: { timeout: 120_000 } })and accessing it from the middleware like this:
// Timeout middleware
fetchClient.use({
async onRequest({ request, meta: { timeout } }) {
// ...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