fetchify
This package is designed to make the process of interacting with various APIs that have strict limitations more convenient and careful. For example, this could be APIs like Notion or Telegram, which have stringent limits.
👋 👋 ATTENTION!
This package is under development and will be frequently updated. The author would appreciate any help, advice, and pull requests! Thank you for your understanding 😊
Import
Deno:
From deno.land/x:
import fetchify from "https://deno.land/x/fetchify@0.2.6/mod.ts";Or esm.sh:
import fetchify from "https://esm.sh/gh/sevapp/fetchify@0.2.6/mod.ts"
Node.JS:
Install from npm:
npm i --save @sevapp/fetchifyAnd import:
import fetchify from "fetchify";
Usage:
The first thing available to you is the fetchify function
const json = await (await fetchify("https://catfact.ninja/fact")).json();
console.log(json);
This function has a similar interface to the classic fetch but extends it with additional options, for example:
const json = await (await fetchify(
"https://catfact.ninja/fact",
{
timeout: 1000, // Now, the waiting for a response will be interrupted after 1000 ms.
}
)).json();
console.log(json);
But you can also create an instance with a set base URL and rate-limiting constraints:
const jph = fetchify.create({
limiter: {
rps: 3,
interval: 10,
},
baseURL: "https://jsonplaceholder.typicode.com",
headers: {
"hello": "world",
},
});
for (let i = 30; i--;) {
console.log(`send ${i}`);
jph.get(`/posts/${i}`).then((data) => console.log(`${i} ${data.status}`))
.catch((err) => console.log(`${i} ${err}`))
.finally(() => {
});
}