2.0.0 • Published 1 year ago

timed-fetch v2.0.0

Weekly downloads
4
License
UNLICENSE
Repository
-
Last release
1 year ago

timed-fetch

Description

Isomorphic fetch wrapper that allows the setting of a max wait-time for a response, if the wait-time is exceeded a 408 Request Timeout HTTP Status Code will be sent back. This allows developers to handle excessivly long API calls without making the user wait, whether the issue stems from a bad internet connection, or a slow backend service.

Code Example

import timedFetch from 'timed-fetch'

const fetchDataWith4SecondLimit = async () => {
  const options = {
    timeout: 4, // wait 4 seconds max for fetch response.
    method: "GET",
  }

  try {
    const response = await timedFetch("https://example.com/api", options)
    const json = response.json()

    return json
  } catch (err) {
    return new Error(err.message)
  }
}
2.0.0

1 year ago

1.1.0

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

1.0.1

5 years ago

1.0.0

5 years ago