{"id":47656,"library":"fetch-sse","title":"fetch-sse","description":"A lightweight library (v1.2.1) that provides an easy API for consuming Server-Sent Events (SSE) using the Fetch API, with full support for browsers and Node.js (>=18). It offers a single main function `fetchEventData` with familiar fetch-like options, including custom headers, method, body, signal, and event callbacks (onMessage, onOpen, onClose, onError). Key differentiators: no dependencies, TypeScript-first, supports POST requests and custom status handling via `skipStatusCheck`. Regular releases, actively maintained on GitHub.","status":"active","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/yokingma/fetch-sse","tags":["javascript","SSE","Server-Sent","Events","EventSource","fetch","typescript"],"install":[{"cmd":"npm install fetch-sse","lang":"bash","label":"npm"},{"cmd":"yarn add fetch-sse","lang":"bash","label":"yarn"},{"cmd":"pnpm add fetch-sse","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Only named export is available; no default export.","wrong":"import fetchEventData from 'fetch-sse'","symbol":"fetchEventData","correct":"import { fetchEventData } from 'fetch-sse'"},{"note":"TypeScript type for parsed SSE events.","symbol":"ServerSentEvent","correct":"import { ServerSentEvent } from 'fetch-sse'"},{"note":"TypeScript interface for options parameter.","symbol":"IFetchOptions","correct":"import { IFetchOptions } from 'fetch-sse'"}],"quickstart":{"code":"import { fetchEventData } from 'fetch-sse';\nimport process from 'process';\n\nconst url = process.env.SSE_URL ?? 'https://example.com/sse';\nconst token = process.env.API_KEY ?? '';\n\nconst controller = new AbortController();\n\nawait fetchEventData(url, {\n  method: 'POST',\n  headers: {\n    'Content-Type': 'application/json',\n    'Authorization': `Bearer ${token}`\n  },\n  data: { query: 'latest' },\n  signal: controller.signal,\n  onMessage: (event) => {\n    console.log('Received event:', event);\n  },\n  onOpen: (res) => {\n    console.log('Stream opened, status:', res?.status);\n  },\n  onError: (err) => {\n    console.error('Error:', err);\n  },\n  onClose: () => {\n    console.log('Stream closed');\n  }\n});\n\n// Abort after 10 seconds\nsetTimeout(() => controller.abort(), 10000);","lang":"typescript","description":"Demonstrates basic usage of fetchEventData with POST request, Bearer token auth, and event callbacks. Includes abort signal and environment variable for URL and API key."},"warnings":[{"fix":"Set skipStatusCheck: true to handle custom status codes manually.","message":"Default status check rejects non-2xx responses; onOpen is not called for non-2xx unless skipStatusCheck is true.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `data: JSON.stringify({...})` if you need explicit control, or pass a string as is.","message":"The `data` option is automatically JSON-stringified if it is an object; to send a string body directly, pass a string (e.g., 'plain text').","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"N/A","message":"No deprecated features identified in current version.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'18':31 'activ':76 'api':12,23 'bodi':49 'browser':28 'callback':53 'consum':14 'custom':46,69 'depend':61 'differenti':59 'easi':11 'event':18,52,85 'eventsourc':86 'familiar':40 'fetch':2,22,42,87 'fetch-lik':41 'fetch-ss':1 'fetcheventdata':38 'first':64 'full':25 'function':37 'github':79 'handl':71 'header':47 'includ':45 'javascript':80 'key':58 'librari':6 'lightweight':5 'like':43 'main':36 'maintain':77 'method':48 'node.js':30 'offer':33 'onclos':56 'onerror':57 'onmessag':54 'onopen':55 'option':44 'post':66 'provid':9 'regular':74 'releas':75 'request':67 'sent':17,84 'server':16,83 'server-s':15,82 'signal':50 'singl':35 'skipstatuscheck':73 'sse':3,19,81 'status':70 'support':26,65 'typescript':63,88 'typescript-first':62 'use':20 'v1.2.1':7 'via':72","created_at":"2026-06-07T16:52:37.094776+00:00","updated_at":"2026-06-07T16:52:37.094776+00:00","problems":[{"fix":"Use `import { fetchEventData } from 'fetch-sse'` instead of `import fetchEventData from 'fetch-sse'`.","cause":"Using default import instead of named import.","error":"TypeError: fetchEventData is not a function"},{"fix":"Upgrade Node.js to >=18 or install a polyfill like `fast-text-encoding`.","cause":"Running in an older Node.js version (<18) or browser without TextDecoder polyfill.","error":"ReferenceError: TextDecoder is not defined"},{"fix":"Add `skipStatusCheck: true` to options if you want to handle non-2xx responses in onOpen.","cause":"The server responded with a status code outside 200-299 and skipStatusCheck is not enabled.","error":"Error: Event stream returned non-2xx status code"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/yokingma/fetch-sse#readme","github":"https://github.com/yokingma/fetch-sse","docs":null,"changelog":null,"pypi":null,"npm":"fetch-sse","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}