# strapi.fetch 使用原生 fetch() API

> Source: https://strapi.nodejs.cn/cms/migration/v4-to-v5/breaking-changes/fetch

🌐 `strapi.fetch` uses the native `fetch()` API

在 Strapi 5 中，`strapi.fetch` 封装了原生的 `fetch()` API，而不是 node-fetch，因此需要将 `timeout` 参数替换为 `signal: AbortSignal.timeout()`。

🌐 In Strapi 5, `strapi.fetch` wraps the native `fetch()` API instead of node-fetch, requiring the `timeout` parameter to be replaced with `signal: AbortSignal.timeout()`.

在 Strapi 5 中，`strapi.fetch` 对象现在封装的是 Node Fetch API，而不是 node-fetch。

🌐 In Strapi 5, the `strapi.fetch` object is now wrapping node Fetch API instead of node-fetch.

此页面是[重大更改数据库](/cms/migration/v4-to-v5/breaking-changes)的一部分，提供关于重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的附加说明。

🌐 This page is part of the [breaking changes database](/cms/migration/v4-to-v5/breaking-changes) and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

- Is this breaking change affecting plugins? Yes
- Is this breaking change automatically handled by a codemod? No

## 重大变更描述 {#breaking-change-description}

🌐 Breaking change description

**在 Strapi v4 中**

Strapi.fetch 封装了 node-fetch 的 `fetch()` 并接受相同的参数。

🌐 Strapi.fetch wrapped node-fetch’s `fetch()` and accepted the same parameters.

**在 Strapi 5 中**

`node-fetch` 模块不再使用。`strapi.fetch` 调用原生的 `fetch()` 方法。

🌐 The `node-fetch` module is not used anymore. `strapi.fetch` calls the native `fetch()` method.

## 迁移 {#migration}

🌐 Migration

<br/>

### 注意 {#notes}

🌐 Notes

* 这些参数大多兼容，但也存在一些差异。

### 手动操作 {#manual-procedure}

🌐 Manual procedure

如果你的 Strapi v4 代码将 `timeout` 参数传递给 `strapi.fetch`，请将其替换为如下的信号属性：

🌐 If your Strapi v4 code passed the `timeout` parameter to `strapi.fetch`, replace it with a signal property as follows:

**在 Strapi v4 中**

```tsx
strapi.fetch(url, {
  method: 'POST',
  body,
  headers,
  timeout: 1000,
}); // accepts the type RequestInit from node-fetch
```

**在 Strapi 5 中**

```tsx
strapi.fetch(url, {
  method: 'POST',
  body,
  headers,
  signal: AbortSignal.timeout(1000)
}); // accepts the type RequestInit native to Node
```
