Socket
Book a DemoInstallSign in
Socket

fetch-streaming

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-streaming

Simple XMLHTTPRequest-based `fetch` implementation for streaming content.

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

fetch-streaming

Simple XMLHTTPRequest-based fetch implementation for streaming content.

60 LOC and no dependencies, works in all browsers.

This is not a replacement for fetch - there is no API match.

Install

npm install --save fetch-streaming

Usage

const fetchS = require('fetch-streaming');

// Would be executed for every new chunk of data.
fetchS('/api/stream', stream => console.log(stream));

// Options
const options = {method: 'POST', headers: {'Content-Type': 'BS'}};
fetchS('/api/stream', options, stream => console.log(stream));

// Promise is returned.
const result = fetchS('/api/stream');
result.then(response => {console.log(response.body)}, error => {console.error(error)})

Tips

Example of server-side express.js infinite endpoint.

app.get('/api/stream', (req, res) => {
  res.write(Date.now().toString());

  // Send new data every second.
  setInterval(() => {
    res.write(Date.now().toString());
  }, 1000);
});

License

MIT

Keywords

fetch

FAQs

Package last updated on 10 Feb 2017

Did you know?

Socket

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.

Install

Related posts