Skip to main content

fetchWithTimeout

Sends a fetch request to a specified URL with a timeout. If the request does not complete within the specified timeout, it is aborted.

Parameters

ParameterTypeOptionalDefaultDescription
urlRequestInfofalseA string representing the URL for fetching.
optionsRequestInittrue{ }Options for the HTTP(S) request.
timeoutnumbertrue5000Time measured in milliseconds.

Returns

Promise<Response>

Example

fetchWithTimeout("https://google.com/", {}, 2000); // Promise<Response>