https://github.com/compwright/axios-header-interceptor
https://github.com/compwright/axios-header-interceptor
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/compwright/axios-header-interceptor
- Owner: compwright
- License: mit
- Created: 2022-10-05T20:24:48.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-02T19:22:26.000Z (about 1 year ago)
- Last Synced: 2025-03-27T14:47:29.953Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.18 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# axios-header-interceptor
[](https://www.npmjs.com/package/axios-header-interceptor)
[](https://github.com/sponsors/compwright)
A tiny [axios](https://www.npmjs.com/package/axios) interceptor for adding request headers.
## Installation
With NPM:
```bash
npm install --save axios-header-interceptor
```
With Yarn:
```bash
yarn add axios-header-interceptor
```
## Example usage
```javascript
import axios from 'axios'
import addHeader from 'axios-header-interceptor'
const client = axios.createClient()
client.interceptors.response.use(
addHeader({ 'X-Requested-With': 'myapp/axios' })
)
```
## Adding OAuth 2.0 access token header
```javascript
import axios from 'axios'
import { addOauthHeader } from 'axios-header-interceptor'
const client = axios.createClient()
// Sets the `Authorization: Bearer ACCESS_TOKEN` header
client.interceptors.response.use(
addOauthHeader('ACCESS_TOKEN')
)
```