
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
An easy API for making Event Source requests, with all the features of fetch(), Supports browsers and node.
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
import { fetchEventData } from 'fetch-sse';
await fetchEventData('/api/sse', {
method: 'POST',
data: { foo: 'bar' },
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token'
},
onMessage: (event) => {
console.log(event);
}
})
You can pass in other parameters in a similar way to the Fetch API.
import { fetchEventData } from 'fetch-sse';
await fetchEventData('/api/sse', {
method: 'POST',
// or JSON.stringify({ foo: 'bar' })
data: { foo: 'bar' },
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token'
},
signal: ctrl.signal,
onMessage: (event) => {
console.log(event.data);
}
})
Interface
// fetch options
export interface IFetchOptions {
method?: string;
headers?: HeadersInit | Record<string, any>;
data?: BodyInit | Record<string, any> | null;
signal?: AbortSignal;
onMessage?: (event: ServerSentEvent | null, done?: boolean) => void;
onOpen?: (res?: Response) => void;
onClose?: () => void;
onError?: (error: any) => void;
}
// decoded event
export interface ServerSentEvent {
event: string | null;
data: string;
raw: string[];
}
The event stream is a simple stream of text data that encoded using UTF-8. You can find more information here.
raw:
data: {"username": "bobby", "time": "02:33:48"}\n\n
parsed:
{
event: null,
data: '{"username": "bobby", "time": "02:33:48"}',
raw: [
'data: {"username": "bobby", "time": "02:33:48"}'
]
}
raw:
:HTTP\n
id: 1\n
event: result\n
data: {"username": "bobby", "time": "02:33:48"}\n\n
parsed:
{
event: 'result',
data: {"username": "bobby", "time": "02:33:48"},
raw: [
':HTTP',
'id: 1',
'event: result',
'data: {"username": "bobby", "time": "02:33:48"}'
]
}
this package is written in typescript and compatible with browsers and nodejs, You might need to polyfill TextDecoder for old versions of browsers.
FAQs
An easy API for making Event Source requests, with all the features of fetch(), Supports browsers and node.
The npm package fetch-sse receives a total of 0 weekly downloads. As such, fetch-sse popularity was classified as not popular.
We found that fetch-sse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.