JSPM

auto-abortable-fetch

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q15412F
  • License ISC

Automatically interrupt the last same http request

Package Exports

  • auto-abortable-fetch
  • auto-abortable-fetch/dist/auto-abortable-fetch.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (auto-abortable-fetch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

auto-abort-fetch.js

Pre-requisites

You can use it on Node 17.5.0 (or later) or a browser version that supports fetch.

Usage

let [res, err] = await autoAbortableFetch({
    url: 'https://xxx',
    method: 'get',
    headers: {},
    timeout: 5000,
    querys: {},
    data: {},
    responseType: 'json',
});
let { headers, success, data, status, statusText } = res;
let { name, message } = err;

// If you want to manually control the fetch abort, you can pass AbortControl.signal

let controller = new AbortController();
let signal = controller.signal;
let [res, err] = await autoAbortableFetch({
    url: 'https://xxx',
    signal,
});

TypeScript usage

interface ResponseData {
    message: string;
}

let [res, err] = await autoAbortableFetch<ResponseData>({ url: 'https://xxx' });
console.log(res.data.message);