Nodejs中request已经被废弃了,有什么替代品吗?
Nodejs中request已经被废弃了,有什么替代品吗?
见 https://github.com/request/request#deprecated
As of Feb 11th 2020, request is fully deprecated. No new changes are expected to land. In fact, none have landed for some time.
For more information about why request is deprecated and possible alternatives refer to this issue.
不知道在 nodejs 中,有哪个比较好的替代品呢?
axios ?
axios
#1
#2
#3
顺便问下,nodejs 如何模拟 form-data 的上传图片啊。
node-fetch
axios 的话,设置好 headers 的 content type,data 用 qs.stringify 就行了
我还在用 fetch 方便前后端之间复制粘贴
我觉得这种库不更新 没什么不正常
你发的链接里再往下翻翻就有他推荐的替代品。
https://github.com/request/request/issues/3143
node-fetch got axios 都是不错的替代,就看 api 的个人喜好吧
今天看到一个新包 gretch,TS 写的 fetch 封装。
node-fetch 吧, axios proxy 有 bug
没法编辑… 真的难受
axios proxy 我记得最新版修好了
axios 比较好用
Python 的 requests 那么优雅,废弃就有点可惜了吧😂
好像黑底的代码展示有点难以阅读,是否可以优化一下
不是夜间模式的问题,是楼主自己的 css 问题
为啥要 deprecate ?
一直在用 axios
https://github.com/request/request/issues/3142,作者有详细解释
简而言之,历史包袱重,又不想后续版本产生断层。作者新写了个函数式的请求库 bent,支持 nodejs 和浏览器
superagent
我用 umi-request
为啥一个开源项目说废弃就废弃, 是不是很不解, 很气愤~
这里有一个解释
https://github.com/airbnb/native-navigation/issues/145#issuecomment-328772095
翻译一下就是
https://s1.ax1x.com/2020/04/01/G8JdP0.png
P.S react-native navigation 库, 一个看起来还算不错的, 也废弃了~~~
一般 node 常用的就是 API 请求+下载, 不必局限在一个, 我的观点其实是这个
#31
我说的通过 node 将图片上传别的服务器去。。。
…
在Node.js中,request
模块确实已经被废弃,但有多种替代品可供选择。以下是一些常见的替代品及其使用示例:
-
axios
:- 基于Promise的HTTP客户端,适用于浏览器和Node.js。
- 支持并发请求、自动解析JSON数据。
- 安装:
npm install axios
- 使用示例:
const axios = require('axios'); axios.get('https://api.example.com/data') .then(response => console.log(response.data)) .catch(error => console.error(error));
-
node-fetch
:- 将Fetch API带到Node.js中,使用
.then
和await
语法。 - 提供限制重定向次数、响应大小等扩展功能。
- 安装:
npm install node-fetch
- 使用示例:
const fetch = require('node-fetch'); fetch('https://api.example.com/data') .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error));
- 将Fetch API带到Node.js中,使用
-
got
:- 轻量级、直观的HTTP请求库,最初是作为
request
的替代品创建的。 - 不会默认解析JSON,需要指定
responseType: 'json'
。 - 安装:
npm install got
- 使用示例:
const got = require('got'); got('https://api.example.com/data', { responseType: 'json' }) .then(response => console.log(response.body)) .catch(error => console.error(error));
- 轻量级、直观的HTTP请求库,最初是作为
这些替代品各有特点,开发者可根据项目需求和个人习惯选择使用。