strapi.fetch uses the native fetch() API
In Strapi 5, the strapi.fetch object is now wrapping node Fetch API instead of node-fetch.
This page is part of the breaking changes database 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β
In Strapi v4
Strapi.fetch wrapped node-fetchβs fetch() and accepted the same parameters.
In Strapi 5
The node-fetch module is not used anymore. strapi.fetch calls the native fetch() method.
Migrationβ
Notesβ
- The parameters are mostly compatible but there are some differences.
Manual procedureβ
If your Strapi v4 code passed the timeout parameter to strapi.fetch, replace it with a signal property as follows:
In Strapi v4
strapi.fetch(url, {
method: 'POST',
body,
headers,
timeout: 1000,
}); // accepts the type RequestInit from node-fetch
In Strapi 5
strapi.fetch(url, {
method: 'POST',
body,
headers,
signal: AbortSignal.timeout(1000)
}); // accepts the type RequestInit native to Node