fetch
版本历史
| 版本 | 变更 |
|---|---|
| v21.0.0 | 不再是实验的。 |
| v18.0.0 | 不再落后于 |
| v17.5.0, v16.15.0 | 新增于: v17.5.0, v16.15.0 |
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.