stream-post-fetch
v2.1.5
Published
Receive server-sent event streams by sending a POST request
Downloads
5
Readme
Installation and import
Using npm
npm install stream-post-fetch
Using yarn
yarn add stream-post-fetch
Import mode
import FetchData from 'stream-post-fetch'
const FetchData = require('stream-post-fetch')
Use examples
Initialization configuration
const customHeaders = { 'Authorization': `Bearer ${TOKEN}` } const chatFetch = new FetchData(url, customHeaders)
Set request headers according to business requirements
Send POST request
const result = awiat chatFetch.post(data) if (result.success) { console.log('Request successful') } else { console.error('request was aborted:', result.error) }
Receive event stream data
const onMessage = () => { console.log('detail', event.detail) } document.addEventListener('onMessage', onMessage)
Stop receiving event stream
chatFetch.cancel()