2.0.1 • Published 2 years ago

fetchout v2.0.1

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
2 years ago

fetchout - fetch with a timeout

Add request timeouts to fetch() calls.

Install

$ npm install fetchout

Usage

const fetchout = require('fetchout');

// Default timeout for all requests. If not set the default is 60 seconds.
fetchout.defaultTimeout(5000);


(async function() {

    try {
        // default timeout of 5 seconds used
        let response1 = await fetchout('http://httpbin.org/delay/3');
        console.log(`response1 status ${response1.status}`)

        // Set a 7 sec timeout for a GET fetch request
        let response2 = await fetchout('http://httpbin.org/delay/3', 7000);
        console.log(`response2 status ${response2.status}`)

        // Set a 6 sec timeout for a POST fetch request - timeout error
        let response3 = await fetchout('http://httpbin.org/delay/9',
           { method: 'POST', body: '{"foo": "bar"}' }, 6000);
    }
    catch (err) {
        console.log(`${err}`);
    }

})();

License

Apache 2.0 license; see LICENSE.

2.0.1

2 years ago

2.0.0

2 years ago

1.0.1

3 years ago

1.0.0

4 years ago

0.0.1

5 years ago