Axios: Interceptors and Base URL
Create an Axios instance with a baseURL, attach auth tokens in request interceptors, and handle 4xx/5xx errors in response interceptors.
Why Use Axios?
Axios is a popular HTTP client built on XMLHttpRequest. It adds: automatic JSON, request/response interceptors, baseURL config, timeout, and request cancellation tokens. Many teams still prefer it over fetch.
Installing Axios
Install via npm. Browser bundle is around 14KB gzipped.
npm install axiosAll lessons in this course
- Fetch API: GET POST PUT DELETE
- Axios: Interceptors and Base URL
- Error Handling: HTTP Status Codes
- SWR and React Query for Data Caching