{"id":30668898,"url":"https://github.com/wutility/stretto","last_synced_at":"2026-04-15T16:03:11.611Z","repository":{"id":311246017,"uuid":"1043008503","full_name":"wutility/stretto","owner":"wutility","description":"🔥 zero-dependency TypeScript library for streaming HTTP requests with support for Server-Sent Events (SSE), NDJSON, and custom data format","archived":false,"fork":false,"pushed_at":"2025-08-23T01:09:04.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-23T03:33:14.720Z","etag":null,"topics":["deno","event-sourcing","fecth-api","nodejs","openai-api","server-sent-events","sse","sse-client","streaming-data","streams"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/stretto","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/wutility.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2025-08-23T00:49:09.000Z","updated_at":"2025-08-23T01:12:20.000Z","dependencies_parsed_at":"2025-08-23T03:33:16.313Z","dependency_job_id":"c8337813-8835-49e2-8d0f-a63342df25ef","html_url":"https://github.com/wutility/stretto","commit_stats":null,"previous_names":["wutility/stretto"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/wutility/stretto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wutility%2Fstretto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wutility%2Fstretto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wutility%2Fstretto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wutility%2Fstretto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wutility","download_url":"https://codeload.github.com/wutility/stretto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wutility%2Fstretto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273056682,"owners_count":25037886,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"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":["deno","event-sourcing","fecth-api","nodejs","openai-api","server-sent-events","sse","sse-client","streaming-data","streams"],"created_at":"2025-09-01T00:12:00.401Z","updated_at":"2026-04-15T16:03:11.605Z","avatar_url":"https://github.com/wutility.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stretto 🚀\n\nA robust, high-performance TypeScript fetch wrapper with built-in retry logic, exponential backoff, streaming capabilities, and Server-Sent Events (SSE) support.\n\n- Memory Efficiency: Zero-copy streaming and buffer reuse keep memory usage low.\n- Minimal Allocations: Optimized hot paths reduce overhead.\n- Buffer Overflow Protection: Configurable limits prevent memory exhaustion attacks.\n- Data Security: Internal buffers are zeroed out to avoid leaks in memory dumps.\n\n\u003cdiv align=\"center\" style=\"width:100%; text-align:center; margin-bottom:20px;\"\u003e\n  \u003cimg src=\"https://badgen.net/bundlephobia/minzip/stretto\" alt=\"Bundle size\" /\u003e\n  \u003cimg src=\"https://badgen.net/bundlephobia/dependency-count/stretto\" alt=\"Dependency count\" /\u003e\n  \u003cimg src=\"https://badgen.net/npm/v/stretto\" alt=\"Version\" /\u003e\n  \u003cimg src=\"https://badgen.net/npm/dt/stretto\" alt=\"Downloads\" /\u003e\n  \u003cimg src=\"https://data.jsdelivr.com/v1/package/npm/stretto/badge\" alt=\"JSDelivr\" /\u003e\n\u003c/div\u003e\n\n\u003chr /\u003e\n\n## 📦 Installation\n\n```shell\n# npm\nnpm install stretto\n# Deno\ndeno add jsr:@wutility/stretto\n```\n\nOr use the CDN:\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/stretto/dist/index.umd.min.js\"\u003e\u003c/script\u003e\n\u003c!-- window.stretto.default is available --\u003e\n```\n\n## 🚀 Quick Start\n\n### Basic Usage\n\n```typescript\nimport stretto from 'stretto';\n// jsr\n// import stretto, { JSONStreamTransformer } from \"jsr:@wutility/stretto\";\n\n// Simple GET request\nconst response = await stretto('https://jsonplaceholder.typicode.com/todos/1');\nconst data = await response.json();\n```\n\n### With Options\n\n```typescript\nconst response = await stretto('https://api.example.com/data', {\n  retries: 5,\n  timeout: 10000,\n  headers: {'Authorization': 'Bearer token'}\n});\n```\n\n### Streaming Responses\n\n```typescript\nconst response = await stretto('https://stream.wikimedia.org/v2/stream/recentchange', {\n  stream: true\n});\n\n// Use as AsyncIterable\nfor await (const chunk of response) {\n  console.log('Received chunk:', chunk);\n}\n```\n\n### Server-Sent Events (SSE)\n\n```typescript\nimport stretto, { JSONStreamTransformer } from 'stretto';\n\nconst response = await stretto('https://sse.dev/test', {\n  stream: true,\n  transformers: [new JSONStreamTransformer()]\n});\n\nfor await (const event of response) {\n  console.log('SSE Event:', event);\n}\n```\n\n## 📖 API Reference\n\n### `stretto(url, options?)`\n\nMain function for making HTTP requests.\n\n**Parameters:**\n- `url: string | URL` - The URL to fetch\n- `options?: StrettoOptions` - Configuration options\n\n**Returns:** `Promise\u003cStrettoStreamableResponse\u003cT\u003e\u003e`\n\n### StrettoOptions\n\n```typescript\ninterface StrettoOptions extends Omit\u003cRequestInit, 'signal'\u003e {\n  retries?: number;                    // Default: 3\n  timeout?: number;                    // Default: 30000ms\n  backoffStrategy?: (attempt: number) =\u003e number;\n  retryOn?: (error: unknown, response?: Response) =\u003e boolean;\n  stream?: boolean;                    // Default: false\n  transformers?: TransformStream\u003cany, any\u003e[];\n  signal?: AbortSignal;\n}\n```\n\n### JSONStreamTransformer\n\nA specialized transformer for parsing Server-Sent Events with JSON payloads.\n\n```typescript\nimport { JSONStreamTransformer } from 'stretto';\n\nconst transformer = new JSONStreamTransformer({\n  maxBuffer: 8192,        // Maximum line buffer size\n  parseData: true,        // Parse JSON automatically\n  donePrefix: '[DONE]',   // Custom termination marker\n  onBufferOverflow: 'skip', // 'skip' | 'throw'\n  onParseError: 'skip'      // 'skip' | 'throw'\n});\n```\n\n## 🔧 Advanced Usage\n\n### Custom Retry Strategy\n\n```typescript\nconst response = await stretto('https://api.example.com/data', {\n  retries: 5,\n  retryOn: (error, response) =\u003e {\n    // Custom retry logic\n    if (response?.status === 429) return true; // Rate limited\n    if (error instanceof TypeError) return true; // Network error\n    return false;\n  },\n  backoffStrategy: (attempt) =\u003e {\n    // Custom backoff: linear instead of exponential\n    return attempt * 1000;\n  }\n});\n```\n\n### Request Cancellation\n\n```typescript\nconst controller = new AbortController();\n\n// Cancel after 5 seconds\nsetTimeout(() =\u003e controller.abort(), 5000);\n\ntry {\n  const response = await stretto('https://api.example.com/data', {\n    signal: controller.signal\n  });\n} catch (error) {\n  if (error.name === 'AbortError') {\n    console.log('Request was cancelled');\n  }\n}\n```\n\n### Multiple Transform Streams\n\n```typescript\nimport stretto, { JSONStreamTransformer } from 'stretto';\n\nconst response = await stretto('https://sse.dev/test', {\n  stream: true,\n  transformers: [new JSONStreamTransformer()]\n});\n\nfor await (const chunk of stream) {}\n```\n\n## 📊 Performance Features\n\n- **Zero-copy streaming**: No unnecessary data copying during stream processing\n- **Optimized backoff**: Uses bitwise operations for fast exponential calculations\n- **Memory efficient**: Reuses buffers and minimizes allocations\n- **V8 optimized**: Takes advantage of JavaScript engine optimizations\n\n## 🧪 Testing\n\n```bash\nnpm test\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.\n\n## 📄 License\n\nMIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwutility%2Fstretto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwutility%2Fstretto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwutility%2Fstretto/lists"}