Skip to content
TypeWire

@tahanabavi/typefetch

documents v1.10.0

The typed HTTP client every other package is built around.

Retry Engine

TypeFetch includes a built-in retry engine on the client.

ts
client.setRetryConfig({
maxRetries: 3,
backoff: "exponential",
retryCondition: (error, attempt) => {
return error.status !== undefined && error.status >= 500;
},
});

Supported backoff strategies:

StrategyBehavior
fixedSame delay each retry
linearDelay increases linearly
exponentialDelay doubles after each retry

Example:

ts
client.setRetryConfig({
maxRetries: 3,
backoff: "fixed",
});

Timeout and Abort Support

Each request can receive per-call options.

ts
await api.user.getUser(
{
path: { id: "123" },
},
{
timeout: 5000,
},
);

You can also pass an external AbortSignal.

ts
const controller = new AbortController();

await api.user.getUser(
{
path: { id: "123" },
},
{
signal: controller.signal,
},
);

controller.abort();