Skip to main content

Built and signed on GitHub Actions

A module to extend `fetch`.

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
JSR Score
100%
Published
3 months ago (0.6.0)

exFetch (ES)

⚖️ MIT

Deno Land: exfetch GitHub: hugoalh/exfetch-es JSR: @hugoalh/exfetch NPM: @hugoalh/exfetch

An ES (JavaScript & TypeScript) module to extend fetch.

🌟 Features

  • Ability to cache suitable Request-Responses to reduce network usage and response time.
  • Automatically retry on failure requests, preferentially obey the response header Retry-After.
  • Redirect fine control.
  • Simplify URL paginate requests.

🔰 Begin

🎯 Targets

Remote JSR NPM
Bun >= v1.1.0 ✔️
Cloudflare Workers ✔️
Deno >= v1.42.0 ✔️ ✔️ ✔️
NodeJS >= v18.12.0 ✔️
Note

  • It is possible to use this module in other methods/ways which not listed in here, however those methods/ways are not officially supported, and should beware maybe cause security issues.

#️⃣ Resources Identifier

  • Remote - Deno Land:
    https://deno.land/x/exfetch[@{Tag}]/mod.ts
    
  • Remote - GitHub Raw:
    https://raw.githubusercontent.com/hugoalh/exfetch-es/{Tag}/mod.ts
    
  • JSR:
    [jsr:]@hugoalh/exfetch[@{Tag}]
    
  • NPM:
    [npm:]@hugoalh/exfetch[@{Tag}]
    
Note

  • For usage of remote resources, it is recommended to import the entire module with the main path mod.ts, however it is also able to import part of the module with sub path if available, but do not import if:

    • it's path has an underscore prefix (e.g.: _foo.ts, _util/bar.ts), or
    • it is a benchmark or test file (e.g.: foo.bench.ts, foo.test.ts), or
    • it's symbol has an underscore prefix (e.g.: _bar, _foo).

    These elements are not considered part of the public API, thus no stability is guaranteed for them.

  • For usage of JSR or NPM resources, it is recommended to import the entire module with the main entrypoint, however it is also able to import part of the module with sub entrypoint if available, please visit the file jsr.jsonc property exports for available sub entrypoints.

  • It is recommended to use this module with tag for immutability.

🛡️ Runtime Permissions

  • Network [Deno: net]
    • Resources

🧩 APIs

  • class ExFetch {
      constructor(options?: ExFetchOptions);
      single(input: string | URL, init?: RequestInit): Promise<Response>;
      urlPaginate(input: string | URL, init?: RequestInit): Promise<Response[]>;
    }
    
  • function exFetch(input: string | URL, init?: RequestInit, options?: ExFetchOptions): Promise<Response>;
    
  • function exFetchURLPaginate(input: string | URL, init?: RequestInit, options?: ExFetchOptions): Promise<Response[]>;
    
Note

✍️ Examples

  • const responses: Response[] = await exFetchURLPaginate("https://api.github.com/repos/microsoft/vscode/labels?per_page=100");
    
    responses.map((response: Response) => {
      return response.ok;
    }).includes(false);
    //=> false (`false` when no broken page, otherwise `true`)
    
    const result = [];
    for (const response of responses) {
      result.push(...(await response.json()));
    }
    result;
    /*=>
    [
      {
        "id": 2339554941,
        "node_id": "MDU6TGFiZWwyMzM5NTU0OTQx",
        "url": "https://api.github.com/repos/microsoft/vscode/labels/:apple:%20si",
        "name": ":apple: si",
        "color": "e99695",
        "default": false,
        "description": "Issues related to apple silicon"
      },
      {
        "id": 421131022,
        "node_id": "MDU6TGFiZWw0MjExMzEwMjI=",
        "url": "https://api.github.com/repos/microsoft/vscode/labels/*as-designed",
        "name": "*as-designed",
        "color": "E2A1C2",
        "default": false,
        "description": "Described behavior is as designed"
      },
      {
        "id": 409283388,
        "node_id": "MDU6TGFiZWw0MDkyODMzODg=",
        "url": "https://api.github.com/repos/microsoft/vscode/labels/*caused-by-extension",
        "name": "*caused-by-extension",
        "color": "E2A1C2",
        "default": false,
        "description": "Issue identified to be caused by an extension"
      },
      {
        "id": 766755777,
        "node_id": "MDU6TGFiZWw3NjY3NTU3Nzc=",
        "url": "https://api.github.com/repos/microsoft/vscode/labels/*dev-question",
        "name": "*dev-question",
        "color": "E2A1C2",
        "default": false,
        "description": "VS Code Extension Development Question"
      },
      {
        "id": 366106217,
        "node_id": "MDU6TGFiZWwzNjYxMDYyMTc=",
        "url": "https://api.github.com/repos/microsoft/vscode/labels/*duplicate",
        "name": "*duplicate",
        "color": "E2A1C2",
        "default": false,
        "description": "Issue identified as a duplicate of another issue(s)"
      },
      ... +467
    ]
    */
    
Built and signed on
GitHub Actions
View transparency log

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hugoalh/exfetch

Import symbol

import * as exfetch from "@hugoalh/exfetch";
or

Import directly with a jsr specifier

import * as exfetch from "jsr:@hugoalh/exfetch";

Add Package

pnpm i jsr:@hugoalh/exfetch
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hugoalh/exfetch

Import symbol

import * as exfetch from "@hugoalh/exfetch";

Add Package

yarn add jsr:@hugoalh/exfetch
or (using Yarn 4.8 or older)
yarn dlx jsr add @hugoalh/exfetch

Import symbol

import * as exfetch from "@hugoalh/exfetch";

Add Package

npx jsr add @hugoalh/exfetch

Import symbol

import * as exfetch from "@hugoalh/exfetch";

Add Package

bunx jsr add @hugoalh/exfetch

Import symbol

import * as exfetch from "@hugoalh/exfetch";