An ES (JavaScript & TypeScript) module to extend fetch
.
- Ability to cache suitable
Request
-Response
s 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.
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.
- 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.
- it's path has an underscore prefix (e.g.:
-
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
propertyexports
for available sub entrypoints. -
It is recommended to use this module with tag for immutability.
- Network [Deno:
net
]- Resources
-
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
- For the full or prettier documentation, can visit via:
-
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 ] */