Node-fetch with built-in response caching.
This repository has been archived on 2023-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
2021-06-11 14:03:26 -04:00
.vscode implement new expanded response caching logic 2021-06-11 14:03:19 -04:00
classes dont error if ejectFromCache is called when the response is already not cached 2021-06-11 14:03:26 -04:00
test dont error if ejectFromCache is called when the response is already not cached 2021-06-11 14:03:26 -04:00
.eslintignore fix lint warnings 2021-06-11 14:03:26 -04:00
.eslintrc.js add boilerplate 2020-04-17 15:40:42 -04:00
.gitignore implement new expanded response caching logic 2021-06-11 14:03:19 -04:00
.npmignore implement new expanded response caching logic 2021-06-11 14:03:19 -04:00
index.js fix lint warnings 2021-06-11 14:03:26 -04:00
LICENSE Create LICENSE 2020-04-17 15:35:46 -04:00
package-lock.json add husky to enforce lint rules and tests 2021-06-11 14:03:26 -04:00
package.json add husky to enforce lint rules and tests 2021-06-11 14:03:26 -04:00
README.md update readme 2020-04-17 17:09:24 -04:00

node-fetch-cache

node-fetch with caching to a directory on disk.

The first usage with any given arguments will result in an HTTP request and any subsequent usage with the same arguments and body function (text, json, buffer, or textConverted) will read the response body from the cache on disk.

Usage

Require it with a directory path to cache in, and then use it the same way you would use fetch.

const fetch = require('node-fetch-cache')('./path/to/cache/dir');

fetch('http://google.com')
  .then(response => response.text())
  .then(text => console.log(text));

API

Note that this does not support the full fetch API. Headers and some other things are not accessible.

async fetch(resource [, init])

Same arguments as browser fetch.

Returns a CachedResponse.

async CachedResponse.text()

Returns the body as a string.

async CachedResponse.json()

Returns the body as a JavaScript object, parsed from JSON.

async CachedResponse.buffer()

Returns the body as a Buffer.

async CachedResponse.textConverted()

Identical to CachedResponse.text(), except instead of always converting to UTF-8, encoding sniffing will be performed and text converted to UTF-8, if possible.

(textConverted requires an optional dependency on npm package encoding, which you need to install manually.