@@ -24,7 +24,7 @@ Find and replace all on all files (CMD+SHIFT+F):
2424
2525<!-- Highlight some of the features your module provide here -->
2626- ✅ Using Fetch instead of XHR
27- - ✅ Built-in adapter for Dedupe, and Priority Queue request.
27+ - ✅ Built-in adapter for Retry, Dedupe, and Priority Queue request.
2828- ✅ Composable hook for Axios interceptors.
2929
3030## Compabilities
@@ -133,26 +133,80 @@ onResponseError(async (error) => {
133133
134134## Queue
135135
136- All request per instance will be add into queue before sent with priority ` 1 ` .
136+ All request per instance will be add into queue before sent with priority MEDIUM ( ` 20 ` ) .
137137If you want to send your request first before the others, you can set using option ` priority ` . The higher priority will run first.
138138
139139``` ts
140+ import { QueuePriority } from ' @privyid/nuapi/core'
141+
140142useApi ().get (' /document/load' , {
141- priority: 2 ,
143+ // Using presets
144+ priority: QueuePriority .HIGH ,
145+ // Or using number
146+ priority: 50 ,
142147})
143148```
144149
145150## Dedupe
146151
147152Sometime, you want to cancel request with same endpoint like when you working with searching or filter.
148153
149- NuAPI has built in function for this case. Just set ` requestId ` , multiple sent request with same id will cancel last request before.
154+ NuAPI has built in function for this case. Just set ` requestkey ` , multiple sent request with same id will cancel last request before.
150155
151156``` ts
152157useApi ().get (' /document/load' , {
153- requestId : ' document-load' ,
158+ requestkey : ' document-load' ,
154159})
155160```
161+
162+ ### Cancel Manually
163+
164+ Cancel spesific request by ` requestKey ` using ` .cancel() `
165+
166+ ``` ts
167+ useApi ().cancel (' document-load' )
168+ ```
169+
170+ Or cancel all requests that have ` requestKey ` using ` .cancelAll() `
171+
172+ ``` ts
173+ useApi ().cancelAll ()
174+ ```
175+
176+ ## Retry
177+
178+ NuAPI automatically retries request when got an error with status code:
179+
180+ - 408 - Request Timeout
181+ - 409 - Conflict
182+ - 425 - Too Early
183+ - 429 - Too Many Requests
184+ - 500 - Internal Server Error
185+ - 502 - Bad Gateway
186+ - 503 - Service Unavailable
187+ - 504 - Gateway Timeout
188+
189+ By default will retries ` 3 ` times (except for ` PATCH ` , ` POST ` , ` PUT ` , ` DELETE ` ) can be changed using option ` retry ` .
190+
191+ ``` ts
192+ useApi ().get (' /document/load' , {
193+ retry: 5 ,
194+ })
195+ ```
196+
197+ ### Customize Retry Condition
198+
199+ You can customize when request should retries using ` retryOn `
200+
201+ ``` ts
202+ useApi ().get (' /document/load' , {
203+ retryOn (error ) {
204+ return getCode (error ) === 423
205+ && error .config .retryCount < 3
206+ },
207+ })
208+ ```
209+
156210## API
157211
158212👉 You can learn more about usage in [ JSDocs Documentation] ( https://www.jsdocs.io/package/@privyid/nuapi ) .
0 commit comments