@npora/request 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/dist/index.cjs +620 -50
- package/dist/index.d.cts +110 -9
- package/dist/index.d.ts +110 -9
- package/dist/index.js +619 -50
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,6 +145,17 @@ const user = await request.get<User>('/users/1', {
|
|
|
145
145
|
cache.clear()
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
+
Equivalent concurrent cache-enabled requests share one network operation by
|
|
149
|
+
default. Pass a custom `CacheStore` to share cached entries across clients or
|
|
150
|
+
connect an external storage system:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
const cache = cachePlugin({
|
|
154
|
+
store: sharedStore,
|
|
155
|
+
dedupe: true
|
|
156
|
+
})
|
|
157
|
+
```
|
|
158
|
+
|
|
148
159
|
Built-in plugins:
|
|
149
160
|
|
|
150
161
|
- `retryPlugin()`
|
|
@@ -189,6 +200,24 @@ api.interceptors.error.use(error => error)
|
|
|
189
200
|
An optional numeric priority controls execution order. Higher priorities run
|
|
190
201
|
first; equal priorities preserve registration order.
|
|
191
202
|
|
|
203
|
+
## Request testing
|
|
204
|
+
|
|
205
|
+
`MockAdapter` supports method-aware routes, dynamic or one-time responses,
|
|
206
|
+
query/header matching, delay, timeout and network-error simulation, and request
|
|
207
|
+
history:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
const adapter = new MockAdapter()
|
|
211
|
+
|
|
212
|
+
adapter
|
|
213
|
+
.onGet('/users/1')
|
|
214
|
+
.replyOnce(503, { message: 'busy' })
|
|
215
|
+
.onGet('/users/1')
|
|
216
|
+
.reply(200, { id: 1, name: 'Npora' })
|
|
217
|
+
|
|
218
|
+
const api = createClient({ adapter })
|
|
219
|
+
```
|
|
220
|
+
|
|
192
221
|
## Errors
|
|
193
222
|
|
|
194
223
|
```ts
|