{"id":26920534,"url":"https://github.com/fgiova/undici-rest-client","last_synced_at":"2026-03-10T04:31:19.339Z","repository":{"id":218132122,"uuid":"745423897","full_name":"fgiova/undici-rest-client","owner":"fgiova","description":"A simple generic REST client using undici","archived":false,"fork":false,"pushed_at":"2025-09-08T09:20:29.000Z","size":309,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-08T10:29:17.812Z","etag":null,"topics":["client","rest","undici"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fgiova.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-19T09:58:26.000Z","updated_at":"2025-09-08T09:20:32.000Z","dependencies_parsed_at":"2024-01-19T22:58:28.760Z","dependency_job_id":"dab7bc36-e604-477c-b226-12d3595f800f","html_url":"https://github.com/fgiova/undici-rest-client","commit_stats":null,"previous_names":["fgiova/undici-rest-client"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/fgiova/undici-rest-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgiova%2Fundici-rest-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgiova%2Fundici-rest-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgiova%2Fundici-rest-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgiova%2Fundici-rest-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fgiova","download_url":"https://codeload.github.com/fgiova/undici-rest-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgiova%2Fundici-rest-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30324386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T01:36:58.598Z","status":"online","status_checked_at":"2026-03-10T02:00:06.579Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["client","rest","undici"],"created_at":"2025-04-01T22:37:33.765Z","updated_at":"2026-03-10T04:31:19.327Z","avatar_url":"https://github.com/fgiova.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple REST client using undici\n\n[![NPM version](https://img.shields.io/npm/v/@fgiova/undici-rest-client.svg?style=flat)](https://www.npmjs.com/package/@fgiova/undici-rest-client)\n![CI workflow](https://github.com/fgiova/undici-rest-client/actions/workflows/node.js.yml/badge.svg)\n[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)\n[![Linted with Biome](https://img.shields.io/badge/Linted_with-Biome-60a5fa?style=flat\u0026logo=biome)](https://biomejs.dev)\n[![Maintainability](https://qlty.sh/gh/fgiova/projects/undici-rest-client/maintainability.svg)](https://qlty.sh/gh/fgiova/projects/undici-rest-client)\n[![Code Coverage](https://qlty.sh/gh/fgiova/projects/undici-rest-client/coverage.svg)](https://qlty.sh/gh/fgiova/projects/undici-rest-client)\n\n\n## Description\nThis is a simple REST client using [undici](https://www.npmjs.com/package/undici) as http client.\u003cbr\u003e\nIt's support a simple retry mechanism using exponential backoff or using delay based on retry-after HTTP header \nIt's implement a simple LRU cache mechanism on idempotent HTTP methods.\n\n[!NOTE]\nFor node 18 use version 2.x \u003e, version \u003e 4.x support only Node.js \u003e= 20 .\n\n## Installation\n\n```bash\nnpm install @fgiova/undici-rest-client\n```\n\n## Usage\n\n```typescript\nimport RestClient from \"@fgiova/undici-rest-client\";\n\nconst client = new RestClient({\n    baseUrl: \"https://foo.bar.org\",\n    retry: {\n        httpCodes: [503, 429],\n        baseTimeout: 1000,\n        maxTimeout: 10000,\n        maxRetry: 5,\n        backoff: (retryCount) =\u003e 2 ** retryCount * 1000,\n    },\n\tcache: new LRUCache\u003cstring, any\u003e({max: 10})\n});\n\nconst response = await client.get(\"/foo/bar\", {\n    headers: {\n        \"x-foo\": \"bar\",\n    },\n    ttl: 1000,\n    requestKey: \"foo-bar\",\n});\n\nconst response = await client.post(\"/foo/bar\", {\n    headers: {\n        \"x-foo\": \"bar\",\n    },\n    ttl: 1000,\n    requestKey: \"foo-bar\",\n    body: {\n        foo: \"bar\",\n    }\n});\n\nconst responseWHeaders = await client.post(\"/foo/bar\", {\n\theaders: {\n\t\t\"x-foo\": \"bar\",\n\t},\n\tttl: 1000,\n\trequestKey: \"foo-bar\",\n\tbody: {\n\t\tfoo: \"bar\",\n\t},\n\treturnHeaders: true,\n});\n\nconsole.log(response.body); // { foo: \"bar\" }\nconsole.log(response.headers); // { \"x-foo-return\": \"bar\" }\n\n```\n\n## Client Options\n| Option  | Type                  | Default | Description                                   |\n|---------|-----------------------|---------|-----------------------------------------------|\n| baseUrl | string                |         | The base domain url to be used for the client |\n| retry   | Retry Options         |         | The retry options                             |\n| cache   | LRUCache\u003cstring, any\u003e |         | The LRU cache instance                        |\n| undici  | Undici Option         |         | The undici options                            |\n\n## Retry Options\n| Option          | Type                                | Default                      | Description                                   |\n|-----------------|-------------------------------------|------------------------------|-----------------------------------------------|\n| httpCodes       | number[]                            | 502, 503, 429, 408, 504, 599 | The HTTP codes to be retried                  |\n| baseTimeout     | number                              | 300                          | The base timeout in ms                        |\n| maxTimeout      | number                              | 30000                        | The max timeout in ms                         |\n| maxRetry        | number                              | 3                            | The max number of retry                       |\n| backoff         | (retryCount: number) =\u003e number      | exponential backoff          | The backoff function                          |\n\n## Undici Options\n| Option       | Type                           | Default | Description                      |\n|--------------|--------------------------------|---------|----------------------------------|\n| clientOption | Pool.Options                   |         | The number of connections        |\n| pipelining   | number                         |         | The number of pipelining         |\n| interceptors | DispatcherComposeInterceptor[] |         | Array of interceptors for undici |\n\n## RequestOptions\n| Option        | Type                   | Default | Description                                                              |\n|---------------|------------------------|---------|--------------------------------------------------------------------------|\n| headers       | Record\u003cstring, string\u003e |         | The HTTP headers                                                         |\n| body          | any                    |         | The HTTP body                                                            |\n| ttl           | number                 |         | The TTL for the cache                                                    |\n| requestKey    | string                 |         | The key for the cache                                                    |\n| path          | string                 |         | The path for the request                                                 |\n| returnHeaders | boolean                | false   | If true return headers into headers property and body into body property |\n\n\n**Notes**:\u003cbr\u003e\nThe cache is a simple LRU cache with a max size of 1000 items and a default TTL of 30 seconds.\u003cbr\u003e\nThe cache TTL can be overridden using the `ttl` option in the request.\u003cbr\u003e\nThe cache key is generated using the request method, the request path and the request body.\u003cbr\u003e\nThe cache key can be overridden using the `requestKey` option in the request.\u003cbr\u003e\nWhen the request is not idempotent, the cache is disabled.\u003cbr\u003e\nWhen the body is a plain object the header content-type \"application/json\" is added to request.\u003cbr\u003e\nWhen response is a not compressible (typically a binary response) array buffer are returned.\u003cbr\u003e\nParallel idempotent requests at same resource are deduplicated.\u003cbr\u003e\n\n## Methods\n### request\n```typescript\nrequest\u003cT = ArrayBuffer\u003e(options: RequestOptions): Promise\u003cResponse\u003cT\u003e\u003e;\n```\n### get\n```typescript\nget\u003cT = ArrayBuffer\u003e(path: string, options?: Omit\u003cRequestOptions, \"path\" | \"method\" | \"body\" \u003e): Promise\u003cResponse\u003cT\u003e\u003e;\n```\n### post\n```typescript\npost\u003cT = ArrayBuffer\u003e(path: string, options?: Omit\u003cRequestOptions, \"path\" | \"method\"\u003e): Promise\u003cResponse\u003cT\u003e\u003e;\n```\n### put\n```typescript\nput\u003cT = ArrayBuffer\u003e(path: string, options?: Omit\u003cRequestOptions, \"path\" | \"method\"\u003e): Promise\u003cResponse\u003cT\u003e\u003e;\n```\n### patch\n```typescript\npatch\u003cT = ArrayBuffer\u003e(path: string, options?: Omit\u003cRequestOptions, \"path\" | \"method\"\u003e): Promise\u003cResponse\u003cT\u003e\u003e;\n```\n### delete\n```typescript\ndelete\u003cT = ArrayBuffer\u003e(path: string, options?: Omit\u003cRequestOptions, \"path\" | \"method\" | \"body\" | \"ttl\"\u003e): Promise\u003cResponse\u003cT\u003e\u003e;\n```\n\n## License\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgiova%2Fundici-rest-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffgiova%2Fundici-rest-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgiova%2Fundici-rest-client/lists"}