A collection of Axios plugins for enhanced functionality.
- Allow 404 Responses: Handle 404 responses gracefully without throwing errors.
- Inflight Cache: Prevent duplicate requests by caching inflight requests.
- Get All Pages: Automatically fetch paginated API results.
Install the package via npm:
npm install @stephenhebert/axios-plugins
Enable the allow404
plugin to handle 404 responses gracefully:
import axios from 'axios'
import { allow404 } from '@stephenhebert/axios-plugins'
const client = axios.create({
plugins: {
allow404: true,
},
})
allow404.install(client)
client.get('http://example.com/api/data')
.then(response => console.log(response.status)) // 404
.catch(error => console.error(error))
Prevent duplicate requests by enabling the inflightCache
plugin:
import axios from 'axios'
import { inflightCache } from '@stephenhebert/axios-plugins'
const client = axios.create({
plugins: {
inflightCache: true,
},
})
inflightCache.install(client)
client.get('http://example.com/api/data')
.then(response => console.log(response.data))
Automatically fetch all paginated results:
import axios from 'axios'
import { getAllPages } from '@stephenhebert/axios-plugins'
const client = axios.create({
plugins: {
getAllPages: true,
},
})
getAllPages.install(client)
client.get('http://example.com/api/data')
.then(response => console.log(response.data))
Run the following command to build the project:
npm run build
Run the tests using Vitest:
npm run test
Lint the codebase using ESLint:
npm run lint
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
- axios
- plugins
- middleware
- interceptors
- http
- typescript
- javascript
- api