You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- add more details and explanation to the timeout and backoff properties
- add more details and explanation to the retryConfig objects and all it's properties including:
- maxRetries
- backoff
- maxDelay
- retryDelay
@@ -143,7 +147,8 @@ const client: Client = new ClientBuilder()
143
147
.build()
144
148
```
145
149
146
-
It is also important to note that we can also chain other middlewares or further configure the default client to suit the specific need of the client being built.
150
+
It is also important to note that we can chain other middlewares or further configure the default client to suit the specific need of the client being built.
Below is a list of all the class methods that can be invoked to add the functionality of a given middleware.
229
234
230
-
### The authMiddleware methods
235
+
1. The authMiddleware creator methods
236
+
- withAnonymousSessionFlow
237
+
- withClientCredentialsFlow
238
+
- withExistingTokenFlow
239
+
- withPasswordFlow
240
+
- withRefreshToken
241
+
2. Other middleware creator methods
242
+
- withHttpMiddleware
243
+
- withUserAgentMiddleware
244
+
- withCorrelationIdMiddleware
245
+
- withQueueMiddlewareware
246
+
- withLoggerMiddleware
247
+
- withMiddleware
248
+
249
+
### 1. The authMiddleware creator methods
231
250
232
251
These are class methods that creates auth middlewares using different authentication flows or method.
233
252
@@ -413,7 +432,7 @@ const client: Client = new ClientBuilder()
413
432
414
433
`-`
415
434
416
-
### Other middlewares
435
+
### 2. Other middleware creator methods
417
436
418
437
There are also other class methods that creates middlewares used to fully cusotmize and control the client, they are described in details below.
419
438
@@ -432,21 +451,38 @@ The HTTP middleware can run in either a browser or Node.js environment. For Node
432
451
5.`maskSensitiveHeaderData` (_Boolean_): flag to mask sensitie data in the header. e.g. Authorization token
433
452
6.`enableRetry` (_Boolean_): flag to enable retry on network errors and 500 response. (Default: false)
434
453
7.`retryConfig` (_Object_): Field required in the object listed below
435
-
8.`maxRetries` (_Number_): number of times to retry the request before failing the request. (Default: 50)
436
-
9.`retryDelay` (_Number_): amount of milliseconds to wait before retrying the next request. (Default: 200)
437
-
10.`backoff` (_Boolean_): activates exponential backoff. Recommended to prevent spamming of the server. (Default: true)
438
-
11.`maxDelay` (_Number_): The maximum duration (milliseconds) to wait before retrying, useful if the delay time grew exponentially more than reasonable
454
+
8.-`maxRetries` (_Number_): number of times to retry the request before failing the request. (Default: 50)
455
+
9.-`retryDelay` (_Number_): amount of milliseconds to wait before retrying the next request. (Default: 200)
456
+
10.-`backoff` (_Boolean_): activates exponential backoff. Recommended to prevent spamming of the server. (Default: true)
457
+
11.-`maxDelay` (_Number_): The maximum duration (milliseconds) to wait before retrying, useful if the delay time grew exponentially more than reasonable
439
458
12.`fetch` (_Function_): A fetch implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function
440
459
13.`timeout` (_Number_): Request/response timeout in ms. Must have globally available or passed in AbortController
441
-
14.`abortController` or `getAbortController` depending on you chose to handle the timeout (`abortController`): This property accepts the `AbortController` instance. Could be [abort-controller](https://www.npmjs.com/package/abort-controller) or globally available one.
460
+
14.`getAbortController` depending on you chose to handle the timeout (`abortController`): This property accepts the `AbortController` instance. Could be [abort-controller](https://www.npmjs.com/package/abort-controller) or globally available one.
461
+
462
+
#### Note:
463
+
464
+
The `arbortController` property is deprecated, use the `getAbortController` property instead.
442
465
443
466
#### Retrying requests
444
467
445
-
This modules have a retrying ability incase of network failures or 503 response errors. To enable this behavior, pass the `enableRetry` flag in the options and also set the maximum number of retries (`maxRetries`) and amount of milliseconds to wait before retrying a request (`retryDelay`).
468
+
This modules have a retrying ability incase of network failures or 503 response errors. To enable this behavior, pass the `enableRetry` flag in the options and also set the maximum number of retries (`maxRetries`) and amount in milliseconds to wait before retrying a request (`retryDelay`).
446
469
447
470
The repeater implements an `exponential` delay, meaning the wait time is not constant and it grows on every retry.
448
471
449
-
##### Token caching
472
+
#### retryConfig
473
+
474
+
This is an object that defines the properties needed to properly configure the retry logic. This configuration only works if the `enableRetries` property is set to `true`
475
+
476
+
-_maxRetries_ - This property is used to set the number of times the request should retry in an event the previous request failed, the default retries is 50.
477
+
-_retryDelay_ - This set the delay (time in milliseconds) between retries, it is important to choose a number that allow the previous request to fully complete before initiating the next retry assuming the previous request failed.
478
+
-_backoff_ - This is used to configure how the retries should be carried out, setting this property to `true` means the request will backoff for a while before retrying. Assuming the previous retry was done in a 2 seconds (2000 milliseconds) delay, the next retry will be say 4 seconds (4000 milliseconds) and the next 8 seconds (8 milliseconds) etc. It is also advisable to set the `maxDelay` property so delay doesn't grow too large.
479
+
-_maxDelay_ - Used to set the delay time limit for the backoff property, so as to prevent the backoff delay from increasing exponentially to infinity.
480
+
481
+
#### timeout
482
+
483
+
For setting the timeout (in milliseconds) for all http requests or responses in a situation where a request or response might take too long to be processed or completed respectively.
484
+
485
+
#### Token caching
450
486
451
487
The token is retrieved and cached upon the first request made by the client. Then, it gets refreshed when it expires. To utilize this, please make sure you use the same client instance and do not create new ones.
@@ -482,6 +519,7 @@ This is used to signal the retry module to retry the request in an event of a re
482
519
#### Usage example
483
520
484
521
```typescript
522
+
importAbortControllerfrom'abort-controller'
485
523
// Use default options
486
524
const options:HttpMiddlewareOptions= {
487
525
host: testHost,
@@ -596,6 +634,51 @@ cont client: Client = new ClientBuilder()
596
634
597
635
`-`
598
636
637
+
#### withMiddleware(middleware: Middleware)
638
+
639
+
A custom class method that accepts a middleware as a argument which is used to further configure the client. Notice how we called the underlying middleware creator function `createHttpClient` and `createAuthForClientCredentialsFlow` to create the middlewares here. With this one can easily use a custom middleware that serve a specific need.
To build the client after calling the class methods of choice that adds the middleware, we invoke the `build()` as the last method on the `new ClientBuilder()` class instance.
0 commit comments