Skip to content

Commit

Permalink
chore(docs): add fetch adapter docs; (#6407)
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS committed May 19, 2024
1 parent e62099b commit 18b13cb
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
- [🆕 Progress capturing](#-progress-capturing)
- [🆕 Rate limiting](#-progress-capturing)
- [🆕 AxiosHeaders](#-axiosheaders)
- [🔥 Fetch adapter](#-fetch-adapter)
- [Semver](#semver)
- [Promises](#promises)
- [TypeScript](#typescript)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 18b13cb

Please sign in to comment.