axios-wrapped-inside
v1.1.1
Published
A pre-configured Axios instance with interceptors for handling authentication tokens and error responses.
Downloads
7
Readme
axios-wrapped-inside
A pre-configured Axios instance with interceptors for handling authentication tokens and error responses.
Installation
You can install this package using npm or yarn:
npm install axios-wrapped-inside
# or
yarn add axios-wrapped-inside
Usage
In JavaScript
import axiosInstance from 'axios-wrapped-inside';
axiosInstance.get('/endpoint')
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error);
});
In TypeScript
import axiosInstance from 'axios-wrapped-inside';
async function fetchData() {
try {
const data = await axiosInstance.get('/endpoint');
console.log(data);
} catch (error) {
console.error(error);
}
}
fetchData();
Configuration
The Axios instance is pre-configured with a base URL and a timeout of 10 seconds. It also includes request interceptors to add an authorization token from localStorage (if available) and response interceptors to handle common HTTP error statuses.