1.3.2 • Published 3 years ago

@npmsoluto/fetch-enhancers v1.3.2

Weekly downloads
1,306
License
MIT
Repository
-
Last release
3 years ago

fetch-enhancers

A collection of composable enhancers on top of standard js fetch api. Does not include a fetch implementation, you need to bring your owm.

install

yarn add @npmsoluto/fetch-enhancers

usage

import fetch from 'node-fetch'
import {withTimeout,withRetry} from '@npmsoluto/fetch-enhancers'

const fetchWithTimeout = withTimeout(fetch, {
    timeout: {
      requestTimeoutMs: 5000
    }
  }); // *optional* global options 5 seconds timeout

await fetchWithTimeout('http://slow.com/get',{
    enhancers:{
        timeout:{
            requestTimeoutMs: 1000
        }
    }
}) // *optional* per call options 1 second timeout


const fetchWithRetry = withRetry(fetch,{
    retry:{
        minTimeout: 1000, //In MS
        retries: 3,
        factor: 5
    }
}); // *optional* global options (retry is async-retry's options object)

await fetchWithRetry('https://flakey.com/get,{
    retry:{
        minTimeout: 1000, //In MS
        retries: 10,
        factor: 2
    }
}); // *optional* per call options (retry is async-retry's options object)


// compose enhancers

const fetchWithRetryAndTimeout = withRetry(
  withTimeout(fetch, {
    timeout: {
      requestTimeoutMs: 5000
    }
  }),
  {
    retry: {
      minTimeout: 1000, //In MS
      retries: 3,
      factor: 5
    }
  }
);

const fetchWithRetryAndTimeout = withRetry(withTimeout(fetch)); // no global options

// per call options when composing enhancers
await fetchWithRetryAndTimeout('https://slow-and-flakey/get',{
    enhancers:{
        retry:{
            minTimeout: 1000, //In MS
            retries: 3,
            factor: 5
        },
        timeout:{
            requestTimeoutMs: 5000
        }
    }
})
1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta1

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.2

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago