Axios HTTP Client
Axios is a popular promise-based HTTP client for both the browser and Node.js. It simplifies making HTTP requests, handling responses, and integrating with APIs. The current stable version is v1.15.0, with regular patch releases addressing security fixes, bug reports, and compatibility improvements, alongside occasional minor versions.
Common errors
-
DeprecationWarning: url.parse() is deprecated
cause Axios versions prior to v1.15.0 used a deprecated Node.js API, causing deprecation warnings in recent Node.js environments.fixUpgrade to Axios v1.15.0 or later to use the updated internal implementation. -
AxiosError object is missing 'status' field
cause A bug introduced in Axios v1.13.3 caused the 'status' field to be intermittently missing from AxiosError objects.fixUpgrade to Axios v1.13.5 or later to restore the `status` field in `AxiosError`. -
Error: socket hang up (with keep-alive requests and timeouts)
cause A bug in Axios versions prior to v1.13.2 could cause 'socket hang up' errors for keep-alive HTTP requests when timeouts were involved.fixUpgrade to Axios v1.13.2 or later to resolve the 'socket hang up' bug. -
Data stream interrupted for responses with non-OK HTTP statuses
cause A regression in Axios v1.13.0 caused issues where data streams were prematurely interrupted for responses with non-2xx status codes.fixUpgrade to Axios v1.13.1 or later to fix data stream handling for non-OK HTTP responses.
Warnings
- breaking Outgoing HTTP header values are now strictly sanitized (e.g., stripping invalid bytes, CRLF sequences, boundary whitespace). Requests with previously 'malformed' headers may now be rejected or altered.
- gotcha If your application relies on environment-based proxy configurations (`NO_PROXY`/`no_proxy`) or specific CommonJS resolution edge-cases, these behaviors might have changed or require re-validation.
- deprecated Older versions of Axios might trigger Node.js console warnings regarding the use of the deprecated `url.parse()` method.
- breaking A Denial of Service (DoS) vulnerability via the `__proto__` key in `mergeConfig` was patched. Older versions are vulnerable.
Install
-
npm install axios -
yarn add axios -
pnpm add axios
Imports
- axios
import axios from 'axios';
Quickstart
import axios from 'axios';
async function fetchData() {
try {
const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1');
console.log(response.data);
} catch (error: any) {
console.error('Error fetching data:', error.message);
}
}
fetchData();