Skip to content

Commit

Permalink
doc: add interceptor and plugin cleanup documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaotian committed Jul 24, 2024
1 parent b775a4e commit 71c9e55
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ A lite request lib based on **fetch** with plugin support and similar API to axi
- [Auth refresh token plugin(from community)](#auth-refresh-token-pluginfrom-community)
- [Auth refresh token plugin(built-in)](#auth-refresh-token-pluginbuilt-in)
- [Create your own custom plugin](#create-your-own-custom-plugin)
- [Cleanup plugins example](#cleanup-plugins-example)
- [Helper functions](#helper-functions)
- [FAQ](#faq)
- [1. Is **xior** 100% compatiable with `axios`?](#1-is-xior-100-compatiable-with-axios)
Expand Down Expand Up @@ -270,6 +271,12 @@ http.interceptors.request.use((config) => {
http.interceptors.request.use((config) => {
return config;
});

// Cleanup interceptors:
const handler = http.interceptors.request.use((config) => {
return config;
});
http.interceptors.request.eject(handler);
```

Response interceptors:
Expand All @@ -294,6 +301,12 @@ http.interceptors.response.use(
return Promise.reject(error);
}
);

// Cleanup interceptors:
const handler = http.interceptors.response.use((res) => {
return res;
});
http.interceptors.response.eject(handler);
```

### Timeout and Cancel request
Expand Down Expand Up @@ -1268,6 +1281,18 @@ instance.plugins.use(function logPlugin(adapter, instance) {

Check [src/plugins](./src/plugins)

### Cleanup plugins example

```ts
import xior from 'xior';
import errorRetryPlugin from 'xior/plugins/error-retry';
const http = xior.create();

const pluginHandler = http.plugins.use(errorRetryPlugin());

http.plugins.eject(pluginHandler);
```

## Helper functions

**xior** has built-in helper functions, may useful for you:
Expand Down

0 comments on commit 71c9e55

Please sign in to comment.