Socket
Book a DemoInstallSign in
Socket

axios-adapter-fetch

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-adapter-fetch

axios对应fetch请求的适配器, 使用axios的方式操作fetch请求

1.0.7
latest
Source
npmnpm
Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

为什么会写这个

平时工作中一般是用axios, 对其方法属性都比较熟悉了, 而且项目中的相关配置也比较庞大. 现在想使用fetch方法代替XMLHttpRequest, 就想在axios的基础上增加对fetch的支持, 所以写了这个对于fetch的适配器, 无需改动原来的axios接口逻辑, 任何属性方法都是一致且支持的(除了上传进度,这个fetch不支持)

优势

  • 体积小, 压缩后不足1kb
  • 使用fetch代替XMLHttpRequest
  • 完全兼容axios原来方法, 文档见axios官网即可, 无fetch学习负担

安装和使用

安装axios和这个适配器

npm install axios
npm install axios-adapter-fetch

两种方式都可使用(关键在于adapter, 这个即是axios对应fetch的适配器):

  • 创建Axios的新实例,并在配置中传递此适配器
import adapter from 'axios-adapter-fetch';

const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  adapter
  ....
});
  • 在每个请求中传递此适配器
import adapter from 'axios-adapter-fetch';

axios.request({
  url: '/user',
  method: 'get',
  adapter
  ...
})

注:

  • 这个适配器依赖于fetch API, 所以在nodejs中使用前提需要nodejs支持fetch API

Keywords

axios

FAQs

Package last updated on 22 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.