fuse-http-client
What is this repository for?
A utility that allows retrying a function with an exponential delay between attempts - inspired from package
Installation
@appfire/fuse-http-client
Usage
import { FuseHttpClient } from '@appfire/fuse-http-client';
type Body = {
test: string
}
try {
type Body = {
test: string
}
type Response = {
data: string
}
const appKey = 'org.swift.confluence.refapp';
const serviceUrl = 'https://services.sand.bobswift.appfire.app/snapshot/utils/2.0/analytics'
const appApiUrl = 'https://apiconfluence-ref-app-dev.sand-bobswift.appfire.app/api/helloworld'
const fuseConfluenceAnalytics = FuseHttpClient.createInstance('Confluence', {
appKey: appKey,
serviceUrl: serviceUrl,
backOffOptions: {
delayFirstAttempt: true,
jitter: 'full',
logRetry: true,
numOfAttempts: 5,
startingDelay: 100,
timeMultiple: 5
}
})
// Response
// Body
// Params // optional
const responsePost = await fuseConfluenceAnalytics.post<Response,Body>({
test: 'sendAnalytics'
})
console.log("fuseAnalytics", responsePost.data);
const fuseConfluenceApp = FuseHttpClient.createInstance('Confluence', {
appKey: appKey,
serviceUrl: appApiUrl,
backOffOptions: {
delayFirstAttempt: true,
jitter: 'full',
logRetry: true,
numOfAttempts: 5,
startingDelay: 100,
timeMultiple: 5
}
})
// Response
// Params //optional
const responseGet = await fuseConfluenceApp.get<Response>();
console.log("fuseAnalytics", responseGet.data);
} catch (error) {
console.error('Final error', error);
}
BackOffOptions
delayFirstAttempt?: booleanDecides whether the
startingDelayshould be applied before the first call. Iffalse, the first call will occur without a delay.Default value is
false.jitter?: JitterType | stringDecides whether a jitter should be applied to the delay. Possible values are
fullandnone.Default value is
none.maxDelay?: numberThe maximum delay, in milliseconds, between two consecutive attempts.
Default value is
Infinity.numOfAttempts?: numberThe maximum number of times to attempt the function.
Default value is
10.Minimum value is
1.retry?: (e: any, attemptNumber: number) => booleanThe
retryfunction can be used to run logic after every failed attempt (e.g. logging a message, assessing the last error, etc.). It is called with the last error and the upcoming attempt number. Returningtruewill retry the function as long as thenumOfAttemptshas not been exceeded. Returningfalsewill end the execution.Default value is a function that always returns
true.startingDelay?: numberThe delay, in milliseconds, before executing the function for the first time.
Default value is
100ms.timeMultiple?: numberThe
startingDelayis multiplied by thetimeMultipleto increase the delay between reattempts.Default value is
2.