@cachehorse/cached-fetch
v1.0.0
Published
A wrapper around fetch() allowing you to cache all your requests and adding the ability to batch multiple requests.
Readme
@cachehorse / cached-fetch
This package is a small wrapper around fetch(), allowing you to utilise Cache Horse's caching and batching API.
How to use
Installing:
npm install --save @cachehorse/cached-fetchimport CachedFetch from '@cachehorse/cached-fetch'
const { get } = CachedFetch({ apiKey: '<your-api-key>' })
const URLS = [
'https://dummyjson.com/http/200',
'https://dummyjson.com/test'
]
const getOneEndpoint = async () => {
const request = await get('https://dummyjson.com/http/200')
return request.json()
}
const getMultipleEndpoints = async () => {
const request = await get(['https://dummyjson.com/http/200', 'https://dummyjson.com/test'])
return request.json()
}
getOneEndpoint()
getMultipleEndpoints()