mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
chore(docs): add fetch adapter docs; (#6407)
This commit is contained in:
@@ -125,6 +125,7 @@
|
||||
- [🆕 Progress capturing](#-progress-capturing)
|
||||
- [🆕 Rate limiting](#-progress-capturing)
|
||||
- [🆕 AxiosHeaders](#-axiosheaders)
|
||||
- [🔥 Fetch adapter](#-fetch-adapter)
|
||||
- [Semver](#semver)
|
||||
- [Promises](#promises)
|
||||
- [TypeScript](#typescript)
|
||||
@@ -481,10 +482,13 @@ These are the available config options for making requests. Only the `url` is re
|
||||
withCredentials: false, // default
|
||||
|
||||
// `adapter` allows custom handling of requests which makes testing easier.
|
||||
// Return a promise and supply a valid response (see lib/adapters/README.md).
|
||||
// Return a promise and supply a valid response (see lib/adapters/README.md)
|
||||
adapter: function (config) {
|
||||
/* ... */
|
||||
},
|
||||
// Also, you can set the name of the built-in adapter, or provide an array with their names
|
||||
// to choose the first available in the environment
|
||||
adapter: 'xhr' // 'fetch' | 'http' | ['xhr', 'http', 'fetch']
|
||||
|
||||
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
|
||||
// This will set an `Authorization` header, overwriting any existing
|
||||
@@ -1289,6 +1293,7 @@ Sending `Blobs`/`Files` as JSON (`base64`) is not currently supported.
|
||||
## 🆕 Progress capturing
|
||||
|
||||
Axios supports both browser and node environments to capture request upload/download progress.
|
||||
The frequency of progress events is forced to be limited to `3` times per second.
|
||||
|
||||
```js
|
||||
await axios.post(url, data, {
|
||||
@@ -1609,6 +1614,30 @@ The following shortcuts are available:
|
||||
|
||||
- `setContentEncoding`, `getContentEncoding`, `hasContentEncoding`
|
||||
|
||||
## 🔥 Fetch adapter
|
||||
|
||||
Fetch adapter was introduced in `v1.7.0`. By default, it will be used if `xhr` and `http` adapters are not available in the build,
|
||||
or not supported by the environment.
|
||||
To use it by default, it must be selected explicitly:
|
||||
|
||||
```js
|
||||
const {data} = axios.get(url, {
|
||||
adapter: 'fetch' // by default ['xhr', 'http', 'fetch']
|
||||
})
|
||||
```
|
||||
|
||||
You can create a separate instance for this:
|
||||
|
||||
```js
|
||||
const fetchAxios = axios.create({
|
||||
adapter: 'fetch'
|
||||
});
|
||||
|
||||
const {data} = fetchAxios.get(url);
|
||||
```
|
||||
|
||||
The adapter supports the same functionality as `xhr` adapter, **including upload and download progress capturing**.
|
||||
Also, it supports additional response types such as `stream` and `formdata` (if supported by the environment).
|
||||
|
||||
## Semver
|
||||
|
||||
|
||||
Reference in New Issue
Block a user