Gathering detailed insights and metrics for @umijs/fetch-sse
Gathering detailed insights and metrics for @umijs/fetch-sse
An easy API for making Event Source requests, with all the features of fetch(), Supports browsers and node.js
npm install @umijs/fetch-sse
Typescript
Module System
Min. Node Version
Node Version
NPM Version
72.9
Supply Chain
99.4
Quality
83.6
Maintenance
100
Vulnerability
100
License
TypeScript (63.62%)
JavaScript (36.38%)
Total Downloads
322
Last Day
1
Last Week
6
Last Month
47
Last Year
322
13 Stars
61 Commits
2 Forks
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.24
Package Id
@umijs/fetch-sse@1.0.24
Unpacked Size
29.27 kB
Size
8.01 kB
File Count
25
NPM Version
9.6.6
Node Version
18.16.0
Publised On
12 Jun 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
20%
6
Compared to previous week
Last month
38.2%
47
Compared to previous month
Last year
0%
322
Compared to previous year
This package provides an easy API for making Event Source requests with all the features of Fetch API, and supports browsers and Node.js.
For Node.js, v18.0.0 or higher required.
npm install fetch-sse
1import { fetchEventData } from 'fetch-sse'; 2 3await fetchEventData('/api/sse', { 4 method: 'POST', 5 data: { foo: 'bar' }, 6 headers: { 7 'Content-Type': 'application/json', 8 'Authorization': 'Bearer token' 9 }, 10 onMessage: (event) => { 11 console.log(event); 12 } 13})
You can pass in other parameters in a similar way to the Fetch API.
1import { fetchEventData } from 'fetch-sse'; 2 3await fetchEventData('/api/sse', { 4 method: 'POST', 5 data: { foo: 'bar' }, 6 headers: { 7 'Content-Type': 'application/json', 8 'Authorization': 'Bearer token' 9 }, 10 signal: ctrl.signal, 11 onMessage: (event) => { 12 console.log(event.data); 13 } 14})
Interface
1export interface IFetchOptions { 2 method?: string; 3 headers?: HeadersInit | Record<string, any>; 4 data?: Record<string, any>; 5 signal?: AbortSignal; 6 onMessage?: (event: ServerSentEvent | null, done?: boolean) => void; 7 onOpen?: (res?: Response) => void; 8 onClose?: () => void; 9 onError?: (error: any) => void; 10} 11 12// decoded event 13export interface ServerSentEvent { 14 event: string | null; 15 data: string; 16 raw: string[]; 17}
The event stream is a simple stream of text data that encoded using UTF-8. You can find more information here.
raw:
1 2data: {"username": "bobby", "time": "02:33:48"}\n\n
parsed:
1{ 2 event: null, 3 data: '{"username": "bobby", "time": "02:33:48"}', 4 raw: [ 5 'data: {"username": "bobby", "time": "02:33:48"}' 6 ] 7}
raw:
1:HTTP\n 2id: 1\n 3event: result\n 4data: {"username": "bobby", "time": "02:33:48"}\n\n
parsed:
1{ 2 event: 'result', 3 data: {"username": "bobby", "time": "02:33:48"}, 4 raw: [ 5 ':HTTP', 6 'id: 1', 7 'event: result', 8 'data: {"username": "bobby", "time": "02:33:48"}' 9 ] 10}
this package is written in typescript and compatible with browsers and nodejs, You might need to polyfill TextDecoder for old versions of browsers.
No vulnerabilities found.
No security vulnerabilities found.