diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index f221b0e01a..28d8d273ac 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -58,7 +58,7 @@ jobs:
with:
run: node ./bin/pr.js
- name: Create pull request
- uses: peter-evans/create-pull-request@v7
+ uses: peter-evans/create-pull-request@v8
id: cpr
with:
branch: release
diff --git a/.github/workflows/sponsors.yml b/.github/workflows/sponsors.yml
index 5df13dcbaa..54cd872bd5 100644
--- a/.github/workflows/sponsors.yml
+++ b/.github/workflows/sponsors.yml
@@ -44,7 +44,7 @@ jobs:
echo "$CONTENT"
- name: Create pull request
if: ${{ steps.sponsors.outputs.changed == 'true'}}
- uses: peter-evans/create-pull-request@v7
+ uses: peter-evans/create-pull-request@v8
id: cpr
with:
branch: sponsors
diff --git a/ECOSYSTEM.md b/ECOSYSTEM.md
index b0257fe330..35244575ee 100644
--- a/ECOSYSTEM.md
+++ b/ECOSYSTEM.md
@@ -16,10 +16,14 @@ This is a list of axios related libraries and resources. If you have a suggestio
* [axios-api-versioning](https://weffe.github.io/axios-api-versioning) - Add easy to manage api versioning to axios
* [axios-data-unpacker](https://github.com/anubhavsrivastava/axios-data-unpacker) - Axios interceptor that unpacks HTTP responses so that you can focus on actual server data.
* [r2curl](https://github.com/uyu423/r2curl) - Extracts the cURL command string from the Axios object. (AxiosResponse, AxiosRequestConfig)
-* [swagger-taxos-codegen](https://github.com/michalzaq12/swagger-taxos-codegen) - Axios based Swagger Codegen (tailored for typescript)
* [axios-endpoints](https://github.com/renancaraujo/axios-endpoints) - Axios endpoints help you to create a more concise endpoint mapping with axios.
* [axios-multi-api](https://github.com/MattCCC/axios-multi-api) - Easy API handling whenever there are many endpoints to add. It helps to make Axios requests in an easy and declarative manner.
* [axios-url-template](https://github.com/rafw87/axios-url-template) - Axios interceptor adding support for URL templates.
+
+### API clients
+
+* [@hey-api/openapi-ts](https://heyapi.dev/openapi-ts/clients/axios) - The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.
+* [swagger-taxos-codegen](https://github.com/michalzaq12/swagger-taxos-codegen) - Axios based Swagger Codegen (tailored for typescript)
* [zodios](https://www.zodios.org) - Typesafe API client based on axios
### Logging and debugging
diff --git a/README.md b/README.md
index a0c09ec5a3..a915d51fb1 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,8 @@
Best Route Planning And Route Optimization Software
@@ -65,6 +65,7 @@
- [Interceptors](#interceptors)
- [Multiple Interceptors](#multiple-interceptors)
- [Handling Errors](#handling-errors)
+ - [Handling Timeouts](#handling-timeouts)
- [Cancellation](#cancellation)
- [AbortController](#abortcontroller)
- [CancelToken 👎](#canceltoken-deprecated)
@@ -188,13 +189,13 @@ const axios = require('axios/dist/browser/axios.cjs'); // browser commonJS bundl
Using jsDelivr CDN (ES5 UMD browser module):
```html
-
+
```
Using unpkg CDN:
```html
-
+
```
## Example
@@ -921,6 +922,27 @@ axios.get('/user/12345')
});
```
+## Handling Timeouts
+
+```js
+async function fetchWithTimeout() {
+ try {
+ const response = await axios.get('https://example.com/data', {
+ timeout: 5000 // 5 seconds
+ });
+
+ console.log('Response:', response.data);
+
+ } catch (error) {
+ if (axios.isAxiosError(error) && error.code === 'ECONNABORTED') {
+ console.error('❌ Request timed out!');
+ } else {
+ console.error('❌ Error:', error.message);
+ }
+ }
+}
+```
+
## Cancellation
### AbortController
@@ -1082,7 +1104,7 @@ The server will handle it as:
If your backend body-parser (like `body-parser` of `express.js`) supports nested objects decoding, you will get the same object on the server-side automatically
```js
- var app = express();
+ const app = express();
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
@@ -1098,7 +1120,7 @@ If your backend body-parser (like `body-parser` of `express.js`) supports nested
### FormData
-To send the data as a `multipart/formdata` you need to pass a formData instance as a payload.
+To send the data as a `multipart/form-data` you need to pass a formData instance as a payload.
Setting the `Content-Type` header is not required as Axios guesses it based on the payload type.
```js
@@ -1778,6 +1800,25 @@ If use ESM, your settings should be fine.
If you compile TypeScript to CJS and you can’t use `"moduleResolution": "node 16"`, you have to enable `esModuleInterop`.
If you use TypeScript to type check CJS JavaScript code, your only option is to use `"moduleResolution": "node16"`.
+
+You can also create a custom instance with typed interceptors:
+
+```typescript
+import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
+
+const apiClient: AxiosInstance = axios.create({
+ baseURL: 'https://api.example.com',
+ timeout: 10000,
+});
+
+apiClient.interceptors.request.use(
+ (config: InternalAxiosRequestConfig) => {
+ // Add auth token
+ return config;
+ }
+);
+```
+
## Online one-click setup
You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online.
diff --git a/bin/actions/notify_published.js b/bin/actions/notify_published.js
index ddacdec31d..22a50d9432 100644
--- a/bin/actions/notify_published.js
+++ b/bin/actions/notify_published.js
@@ -5,11 +5,11 @@ import fs from 'fs/promises';
const argv = minimist(process.argv.slice(2));
console.log(argv);
-let {tag} = argv;
+let { tag } = argv;
-(async() => {
+(async () => {
if (!tag || tag === true) {
- const {version} = JSON.parse((await fs.readFile('./package.json')).toString());
+ const { version } = JSON.parse((await fs.readFile('./package.json')).toString());
tag = 'v' + version;
} else if (typeof tag !== 'string') {
diff --git a/examples/abort-controller/index.html b/examples/abort-controller/index.html
new file mode 100644
index 0000000000..bd3747ae65
--- /dev/null
+++ b/examples/abort-controller/index.html
@@ -0,0 +1,132 @@
+
+
+
+ axios - abort controller example
+
+
+
+
+
axios.AbortController
+
+
+
+
1. Single Request Cancellation
+
Click "Start Request" to begin a 3-second request. Click "Cancel Request" to abort it.
+
+
+
+
+
+
+
+
+
+
+
2. Search-as-you-type (Race Condition Handling)
+
Type quickly. Previous pending requests will be cancelled automatically.