https://github.com/dakdevs/simple-axios-interceptor
Simplified Axios Interceptors
https://github.com/dakdevs/simple-axios-interceptor
Last synced: 2 months ago
JSON representation
Simplified Axios Interceptors
- Host: GitHub
- URL: https://github.com/dakdevs/simple-axios-interceptor
- Owner: dakdevs
- Created: 2019-06-21T05:50:48.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T00:49:54.000Z (over 2 years ago)
- Last Synced: 2025-02-15T05:25:06.428Z (3 months ago)
- Language: JavaScript
- Size: 277 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Axios Interceptors
## Installation
```bash
# With Yarn
yarn add simple-axios-interceptors# With NPM
npm install simple-axios-interceptors
```## Usage
```js
import axios from 'axios';
import connect from 'simple-axios-interceptor';const instance = axios.create({
baseURL: 'https://api.twitter.com/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});connect(instance, 'twitter')
.onRequest((label, { request }) => {
...
})
.onRequestError((label, { error }) => {
...
})
.onResponse((label, { response }) => {
...
})
.onResponseError((label, { error }) => {
...
});
```## Parameters
### `connect(instance, label)`
- `instance` - Axios Instance
- `label` - **Default:** `null` Instance Label
### `onRequest(callback)`
- `callback` - Passes in `label` and `{ error }`### `onRequestError(callback)`
- `callback` - Passes in `label` and `{ error }`### `onResponse(callback)`
- `callback` - Passes in `label` and `{ error }`### `onResponseError(callback)`
- `callback` - Passes in `label` and `{ error }`