Skip to main content
The Deno 2 Release Candidate is here
Learn more

exFetch (TypeScript)

⚖️ MIT

🗂️ GitHub: hugoalh-studio/exfetch-ts Deno Land: exfetch JSR: @hugoalh/exfetch

🆙 Latest Release Version (Latest Release Date)

A TypeScript module to extend fetch.

This project is inspired from:

🌟 Feature

  • 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.

🎯 Target

  • Bun ^ v1.0.0
  • Cloudflare Workers
  • Deno >= v1.35.0 / >= v1.41.1 (Via JSR)

    🛡️ Require Permission

    • Network (allow-net)
  • NodeJS >= v18.12.0

🔗 Other Edition

🔰 Usage

Via HTTPS

🎯 Supported Target

  • Deno
  1. Import at the script (<ScriptName>.ts):
    • Via Deno Land
      import ... from "https://deno.land/x/exfetch[@<Tag>]/mod.ts";
    • Via DenoPKG
      import ... from "https://denopkg.com/hugoalh-studio/exfetch-ts[@<Tag>]/mod.ts";
    • Via DenoPKG (Legacy)
      import ... from "https://denopkg.com/hugoalh-studio/exfetch-deno[@<Tag>]/mod.ts";
    • Via GitHub Raw (Require Tag)
      import ... from "https://raw.githubusercontent.com/hugoalh-studio/exfetch-ts/<Tag>/mod.ts";
    • Via GitHub Raw (Legacy)(Require Tag)
      import ... from "https://raw.githubusercontent.com/hugoalh-studio/exfetch-deno/<Tag>/mod.ts";
    • Via Pax
      import ... from "https://pax.deno.dev/hugoalh-studio/exfetch-ts[@<Tag>]/mod.ts";
    • Via Pax (Legacy)
      import ... from "https://pax.deno.dev/hugoalh-studio/exfetch-deno[@<Tag>]/mod.ts";

    ℹ️ Note

    Although it is recommended to import the entire module with the main path mod.ts, it is also able to import part of the module with sub path if available, but do not import if:

    • it’s file 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.: export function _baz() {}).

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

Via JSR With Native Support

🎯 Supported Target

  • Deno
  1. Import at the script (<ScriptName>.ts):
    import ... from "jsr:@hugoalh/exfetch[@<Tag>]";

    ℹ️ Note

    Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.

Via JSR With NPM Compatibility Layer Support

🎯 Supported Target

  • Bun
  • Cloudflare Workers
  • NodeJS
  1. Install via console/shell/terminal:
    • Via Bun
      bunx jsr add @hugoalh/exfetch[@<Tag>]
    • Via NPM
      npx jsr add @hugoalh/exfetch[@<Tag>]
    • Via PNPM
      pnpm dlx jsr add @hugoalh/exfetch[@<Tag>]
    • Via Yarn
      yarn dlx jsr add @hugoalh/exfetch[@<Tag>]
  2. Import at the script (<ScriptName>.ts):
    import ... from "@hugoalh/exfetch";

    ℹ️ Note

    Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.

🧩 API (Excerpt)

ℹ️ Note

For the prettier documentation, can visit via:

Class

  • ExFetch
  • HTTPHeaderLink
  • HTTPHeaderRetryAfter

Function

  • exFetch
  • exFetchPaginate

✍️ Example

  • const responses: Response[] = await exFetchPaginate("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
    ]
    */