{"id":15390889,"url":"https://github.com/natemoo-re/ultrafetch","last_synced_at":"2025-04-06T05:16:14.481Z","repository":{"id":50719571,"uuid":"437568529","full_name":"natemoo-re/ultrafetch","owner":"natemoo-re","description":"RFC-7234 compliant caching for any `fetch` implementation","archived":false,"fork":false,"pushed_at":"2022-11-16T23:36:52.000Z","size":165,"stargazers_count":223,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T03:09:09.122Z","etag":null,"topics":["cache","cache-control","etag","fetch","http-cache","node","node-fetch","rfc7234"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/natemoo-re.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-12T14:31:35.000Z","updated_at":"2025-01-24T16:43:17.000Z","dependencies_parsed_at":"2023-01-21T20:35:39.787Z","dependency_job_id":null,"html_url":"https://github.com/natemoo-re/ultrafetch","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natemoo-re%2Fultrafetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natemoo-re%2Fultrafetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natemoo-re%2Fultrafetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natemoo-re%2Fultrafetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/natemoo-re","download_url":"https://codeload.github.com/natemoo-re/ultrafetch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247436286,"owners_count":20938533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cache-control","etag","fetch","http-cache","node","node-fetch","rfc7234"],"created_at":"2024-10-01T15:08:57.665Z","updated_at":"2025-04-06T05:16:14.238Z","avatar_url":"https://github.com/natemoo-re.png","language":"TypeScript","readme":"# `ultrafetch`\n\nModular utilities for enhancing `fetch` behavior. Bring Your Own Fetch implementation supports both [`node-fetch`](https://github.com/node-fetch/node-fetch) and [`unidici`](https://github.com/nodejs/undici)'s `fetch` (globally available in `node@18+`).\n\n## `withCache`\n\nThe `withCache` function enhances `fetch` with [RFC-7234](https://httpwg.org/specs/rfc7234.html) compliant cache behavior. The default cache is a simple in-memory `Map`, but custom `cache`s are also supported.\n\n```js\nimport { withCache } from \"ultrafetch\";\n\nconst enhancedFetch = withCache(fetch);\n```\n\nAny custom `cache` that adheres to a `Map` interface is valid.\n\n```ts\nimport { withCache } from \"ultrafetch\";\n\nclass MyCache implements Map {\n  clear(): void;\n  delete(key: K): boolean;\n  get(key: K): V| undefined\u003e;\n  has(key: K): boolean;\n  set(key: K, value: V): this;\n  readonly size: number;\n}\n\nconst enhancedFetch = withCache(fetch, { cache: new MyCache() });\n```\n\nCustom `cache`s can also use the `AsyncMap` interface, which is the same as a standard `Map` but each method is `async`.\n\n```ts\nimport type { AsyncMap } from \"ultrafetch\";\nimport { withCache } from \"ultrafetch\";\n\nclass MyAsyncCache implements AsyncMap {\n  clear(): Promise\u003cvoid\u003e;\n  delete(key: K): Promise\u003cboolean\u003e;\n  get(key: K): Promise\u003cV | undefined\u003e;\n  has(key: K): Promise\u003cboolean\u003e;\n  set(key: K, value: V): Promise\u003cthis\u003e;\n  readonly size: number;\n}\n\nconst enhancedFetch = withCache(fetch, { cache: new MyAsyncCache() });\n```\n\n### `isCached`\n\nThe `isCached` export can be used to determine if a given `Response` was returned from the cache or not.\n\n```ts\nimport { withCache, isCached } from \"ultrafetch\";\n\nconst enhancedFetch = withCache(fetch);\nconst responseA = await enhancedFetch('https://example.com');\nisCached(responseA) // false\nconst responseB = await enhancedFetch('https://example.com');\nisCached(responseB) // true\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatemoo-re%2Fultrafetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnatemoo-re%2Fultrafetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatemoo-re%2Fultrafetch/lists"}