3.1.3 • Published 7 days ago

@alwatr/fetch v3.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 days ago

Alwatr Fetch

Enhanced fetch API with cache strategy, retry pattern, timeout, helper methods and enhanced types.

Installation

yarn add @alwatr/fetch

Usage

import {fetch} from 'https://esm.run/@alwatr/fetch';

const response = await fetch({
  url: '/api/products',
  queryParameters: {limit: 10},
  timeout: 5_000,
  retry: 3,
  cacheStrategy: 'stale_while_revalidate',
});

if (!response.ok) throw new Error('fetch_failed');

const productList = await response.json();

console.log(productList);

Fetch Options

FetchOptions inherited from the fetch standard parameters and some other...

  • url: Request URL.
  • bodyJson: Body as JS Object.
  • queryParameters: URL Query Parameters as JS Object.
  • timeout: A timeout in ms for the fetch request (default 10_000ms).
  • retry: If fetch response not acceptable or timed out, it will retry the request (default 3).
  • retryDelay: Delay before each retries (default 1_000).
  • removeDuplicate: Simple memory caching for remove duplicate/parallel requests (default never).
    • never: Never use memory caching.
    • always: Always use memory caching and remove all duplicate requests (just by method+url).
    • until_load: Cache parallel requests until request completed (it will be removed after the promise resolved).
    • auto: If CacheStorage was supported use until_load strategy else use always.
  • cacheStrategy: Strategies for caching (default network_only).
    • network_only: Only network request without any cache.
    • network_first: Network first, falling back to cache.
    • cache_only: Cache only without any network request.
    • cache_first: Cache first, falling back to network.
    • stale_while_revalidate: Fastest strategy, Use cached first but always request network to update the cache.
  • revalidateCallback: Revalidate callback for stale_while_revalidate cache strategy.
  • cacheStorageName: Cache storage custom name (default alwatr_fetch_cache).

Read more about standard cache strategies

3.1.3

7 days ago

3.1.2

1 month ago

3.1.1

3 months ago

3.1.0

3 months ago

3.0.0

3 months ago

2.2.1

5 months ago

2.2.0

5 months ago

2.1.4

5 months ago

2.1.5

5 months ago

2.1.3

5 months ago

2.1.2

5 months ago

2.1.1

5 months ago

2.0.8

6 months ago

2.1.0

6 months ago

2.0.3

6 months ago

2.0.2

6 months ago

2.0.5

6 months ago

2.0.4

6 months ago

2.0.7

6 months ago

2.0.6

6 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago

1.0.1

11 months ago

1.0.0

11 months ago

0.32.0

11 months ago

0.31.0

12 months ago

0.30.0

1 year ago

0.29.0

1 year ago

0.28.0

1 year ago

0.26.1

1 year ago

0.27.0

1 year ago

0.21.0

1 year ago

0.20.0

1 year ago

0.19.0

2 years ago

0.17.0

2 years ago

0.18.0

2 years ago

0.26.0

1 year ago

0.25.0

1 year ago

0.24.1

1 year ago

0.24.0

1 year ago

0.23.0

1 year ago

0.22.1

1 year ago

0.22.0

1 year ago

0.14.0

2 years ago

0.15.0

2 years ago

0.16.0

2 years ago

0.12.0

2 years ago

0.13.0

2 years ago

0.11.0

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.2

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago