Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

hugoalh-studio/exfetch-js

Repository files navigation

exFetch (NodeJS)

⚖️ MIT

Release - Latest Release - Pre
GitHub GitHub Latest Release Version (GitHub Latest Release Date) GitHub Latest Pre-Release Version (GitHub Latest Pre-Release Date)
NPM NPM Latest Release Version NPM Latest Pre-Release Version

A NodeJS module to extend fetch.

This project is inspired from:

🌟 Feature

  • Automatically retry on failure requests, preferentially obey the response header Retry-After.
  • Redirect fine control.
  • Simplify URL paginate requests.

🔰 Begin

NodeJS

  • Target Version: >= v18.12.0, &:
    • TypeScript >= v5.1.0 [Development]
  • Require Permission: N/A
  • Registry:
    • NPM
      npm install @hugoalh/exfetch[@<Tag>]
      import ... from "@hugoalh/exfetch";

ℹ️ Notice: It is also able to import part of the module with sub path if available, see file package.json property exports for available sub paths.

🧩 API (Excerpt)

ℹ️ Notice: Documentation is included inside the script file.

Class

  • ExFetch
  • HTTPHeaderLink
  • HTTPHeaderRetryAfter

Function

  • exFetch
  • exFetchPaginate

✍️ Example

  • import { exFetchPaginate } from "@hugoalh/exfetch/exfetch";
    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
    ]
    */

🔗 Other Edition