{"id":25940646,"url":"https://github.com/mrlorentx/accio-js","last_synced_at":"2025-03-04T05:18:22.424Z","repository":{"id":279268851,"uuid":"938253738","full_name":"mrlorentx/accio-js","owner":"mrlorentx","description":"A modern, lightweight HTTP client for Node.js with built-in retry capabilities, timeout handling, and event monitoring.","archived":false,"fork":false,"pushed_at":"2025-02-25T07:19:30.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T07:34:48.787Z","etag":null,"topics":["backoff","http","node-js","retry","timeout"],"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/mrlorentx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-24T16:58:39.000Z","updated_at":"2025-02-25T07:19:25.000Z","dependencies_parsed_at":"2025-02-25T07:35:16.036Z","dependency_job_id":"fd72cbcd-bccf-4f8c-94c8-4028e8f33320","html_url":"https://github.com/mrlorentx/accio-js","commit_stats":null,"previous_names":["mrlorentx/retrieve","mrlorentx/accio-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrlorentx%2Faccio-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrlorentx%2Faccio-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrlorentx%2Faccio-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrlorentx%2Faccio-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrlorentx","download_url":"https://codeload.github.com/mrlorentx/accio-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241787540,"owners_count":20020112,"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":["backoff","http","node-js","retry","timeout"],"created_at":"2025-03-04T05:18:21.780Z","updated_at":"2025-03-04T05:18:22.407Z","avatar_url":"https://github.com/mrlorentx.png","language":"TypeScript","readme":"# Accio-JS\n\nA modern, lightweight HTTP client for Node.js with built-in retry capabilities, timeout handling, and event monitoring. Built on top of Node's native fetch (via undici).\n\n[![Node.js Version](https://img.shields.io/node/v/accio-js)](https://nodejs.org/)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue)](https://www.typescriptlang.org/)\n\n## Features\n\n- 🔄 Automatic retries with exponential backoff\n- ⏱️ Request timeout support\n- 🎯 Configurable retry conditions\n- 🎲 Jitter for distributed systems\n- 📊 Event-based monitoring\n- 💪 Full TypeScript support\n- 🪶 Lightweight with minimal dependencies\n\n## Quick Start\n```typescript\nimport { createHttpClient } from 'accio-js';\n\nconst client = createHttpClient();\n\ntry {\n  const response = await client.get('https://jsonplaceholder.typicode.com/todos/1');\n  const data = await response.json();\n  console.log(data);\n} catch (error) {\n  console.error('Request failed:', error);\n}\n```\n\n## Configuration\n\n```typescript\nconst client = createHttpClient({\n  // Default headers for all requests\n  headers: {\n    'Authorization': 'Bearer token',\n  },\n  \n  // Request timeout in milliseconds\n  timeout: 5000,\n  \n  // Retry configuration\n  retry: {\n    maxRetries: 3,\n    initialDelay: 100,\n    maxDelay: 1000,\n    jitter: 0.1,\n    retryableStatuses: [408, 429, 500, 502, 503, 504],\n    shouldRetry: (error, attempt) =\u003e true,\n  }\n});\n```\n\n### Configuration Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `headers` | `Record\u003cstring, string\u003e` | `{}` | Default headers for all requests |\n| `timeout` | `number` | `undefined` | Request timeout in milliseconds |\n| `retry.maxRetries` | `number` | `3` | Maximum number of retry attempts |\n| `retry.initialDelay` | `number` | `100` | Initial delay between retries (ms) |\n| `retry.maxDelay` | `number` | `1000` | Maximum delay between retries (ms) |\n| `retry.jitter` | `number` | `0.1` | Random delay factor (0-1) |\n| `retry.retryableStatuses` | `number[]` | `[408, 429, 500, 502, 503, 504]` | HTTP status codes that trigger retries |\n| `retry.shouldRetry`| `(error, attempt) =\u003e boolean`| `() =\u003e true` | Custom retry function. Return `true` to retry for `retryableStatuses` using your own logic |\n\n## Event Monitoring\n\nMonitor request lifecycle events:\n\n```typescript\nclient.on('request:start', (url, init) =\u003e {\n  console.log(`Starting request to ${url}`);\n});\n\nclient.on('request:end', (url, response, duration) =\u003e {\n  console.log(`Request completed in ${duration}ms`);\n});\n\nclient.on('request:error', (url, error, attempt) =\u003e {\n  console.error(`Request failed (attempt ${attempt}):`, error);\n});\n\nclient.on('request:retry', (url, error, attempt) =\u003e {\n  console.log(`Retrying request (attempt ${attempt})`);\n});\n```\n\n## API Reference\n\n### HTTP Methods\n\n- `client.get(url, init?)`\n- `client.post(url, init?)`\n- `client.put(url, init?)`\n- `client.delete(url, init?)`\n- `client.patch(url, init?)`\n- `client.fetch(url, init?)` - Direct fetch with full request options\n\nAll methods return a `Promise\u003cResponse\u003e` compatible with the Fetch API.\n\n### Events\n\n- `request:start` - Emitted when a request begins\n- `request:end` - Emitted when a request successfully completes\n- `request:error` - Emitted when a request fails\n- `request:retry` - Emitted before a retry attempt\n\n## Cookbook \u0026 Examples\n\n### Using with Hono\nSee [Hono example README](examples/hono/README.md)\n\n### Using with Express\nSee [Express example README](examples/express/README.md)\n\n### Pushing metrics on events\n\n```typescript\nimport { createHttpClient } from 'accio-js';\nimport { metrics } from 'datadog-metrics';\n\n// Configure Datadog\nmetrics.init({ host: 'myapp', prefix: 'http.' });\n\nconst client = createHttpClient();\n\n// Track request durations\nclient.on('request:end', (url, response, duration) =\u003e {\n  const urlPath = new URL(url).pathname;\n  metrics.histogram('request.duration', duration, {\n    path: urlPath,\n    status: response.status.toString(),\n  });\n});\n\n// Track errors\nclient.on('request:error', (url, error) =\u003e {\n  const urlPath = new URL(url).pathname;\n  metrics.increment('request.error', 1, {\n    path: urlPath,\n    error: error.name,\n  });\n});\n\n// Track retries\nclient.on('request:retry', (url, error, attempt) =\u003e {\n  const urlPath = new URL(url).pathname;\n  metrics.increment('request.retry', 1, {\n    path: urlPath,\n    attempt: attempt.toString(),\n  });\n});\n```\n## Todos\n\n- Implement cookbook examples\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrlorentx%2Faccio-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrlorentx%2Faccio-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrlorentx%2Faccio-js/lists"}