Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing Fetch API default timeout

I'm sending queries to my server using native fetch from Google Chrome or Mozilla Firefox:

fetch(url, {
  method: 'POST',
  body: formData,
  credentials: 'include'
})

I set up a server to send a response after 3 minutes and realized that both browsers only wait 2 minutes. Firefox resend the request once more before failing.

Is there a way to define a timeout bigger than 2 minutes (say infinite)?

like image 782
Cichelero Avatar asked May 22 '18 14:05

Cichelero


People also ask

Does fetch have a default timeout?

By default a fetch() request timeouts at the time setup by the browser. In Chrome, for example, this setting equals 300 seconds. That's way longer than a user would expect for a simple network request to complete. A good approach when making network requests is to configure a request timeout of about 8 - 10 seconds.

How do I increase my fetch timeout?

To set request timeout with Fetch API, we can use the AbortController constructor. const controller = new AbortController(); const timeoutId = setTimeout(() => controller. abort(), 5000); const req = async () => { const response = await fetch(url, { signal: controller.

What is the default timeout for API call?

The default timeout is 10 seconds. The minimum is 1 millisecond and the maximum is 120 seconds. If the callout is timing out, please try and increase the timeout on the HTTP request to avoid that.

How do you time out an API?

For the API as a whole, you set a timeout of 30 seconds. For /resource1 , you set a 10-second timeout for the resource as a whole, but you also set a 40-second timeout for the POST operation and a 20-second timeout for the GET operation.


1 Answers

As far as I read fetch()'s documentation on MDN, it does not have any way to specify a timeout.

You can use request or axios module if you are using nodejs. or you can use XMLHttpRequest (plain javascript in browser).

For more information HTTP request timeouts in JavaScript

like image 148
Akshay Garg Avatar answered Oct 13 '22 20:10

Akshay Garg