-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5de326
commit 06d9979
Showing
5 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Interceptor | ||
|
||
## Applying | ||
|
||
This library is based on axios interceptors, so, under the hood, it uses | ||
`axios.interceptors.use()` to apply the interceptors. But you don't. All you have to do is | ||
call `setupCache` and you are ready to go! | ||
|
||
```js | ||
import { setupCache } from 'axios-cache-interceptor'; | ||
|
||
setupCache(axios); | ||
``` | ||
|
||
### How to get the axios instance | ||
|
||
There are two types of axios instances, the `AxiosStatic` and the `AxiosInstance`. The | ||
`AxiosStatic` is the default instance of axios. The `AxiosInstance` is the instance you | ||
get when you call `axios.create()`. | ||
|
||
Both of them work seamlessly, but when messing with the axios static, your hole code, | ||
_including those libraries you don't know that their exists_, are also affected. **You | ||
should be careful when using it.** | ||
|
||
```js | ||
// AxiosStatic | ||
import axios from 'axios'; | ||
|
||
// AxiosInstance | ||
const instance = axios.create(); | ||
``` | ||
|
||
## Customizing behaviors | ||
|
||
You can customize the behaviors of this library in two ways, in a | ||
[per request](pages/per-request-configuration.md) or in a | ||
[global](pages/global-configuration.md) way. | ||
|
||
```js | ||
import Axios from 'axios'; | ||
|
||
const instance = Axios.create({ | ||
/** Here you can pass the axios options * */ | ||
}); | ||
|
||
// Global | ||
setupCache(instance, { | ||
/** Here you can pass the interceptor options * */ | ||
}); | ||
|
||
// Per request | ||
await instance.get('url', { | ||
/** Override axios options * */ | ||
cache: { | ||
/** Override cache options * */ | ||
} | ||
}); | ||
``` |