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 |
---|
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