@jswork/sse-fetch
v1.0.3
Published
Server Sent Event (SSE) streaming via `fetch`.
Downloads
26
Readme
sse-fetch
Server Sent Event (SSE) streaming via
fetch
.
installation
npm install @jswork/sse-fetch
usage
import sseFetch from '@jswork/sse-fetch';
sseFetch('https://example.com/stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: 'hello' }),
parserOptions: {
type: 'prefixedJson',
},
onMessage: function(event) {
console.log(event.data);
},
onClose: function() {
console.log('close');
},
});
license
Code released under the MIT license.