fetch
稳定性: 2 - 稳定的
¥Stability: 2 - Stable
fetch()
函数的浏览器兼容实现。
¥A browser-compatible implementation of the fetch()
function.
const res = await fetch('https://nodejs.cn/api/documentation.json');
if (res.ok) {
const data = await res.json();
console.log(data);
}
该实现基于 undici,这是一个为 Node.js 从头编写的 HTTP/1.1 客户端。你可以通过读取 process.versions.undici
属性来确定 Node.js 进程中打包了哪个版本的 undici
。
¥The implementation is based upon undici, an HTTP/1.1 client
written from scratch for Node.js. You can figure out which version of undici
is bundled
in your Node.js process reading the process.versions.undici
property.