1.0.0-alpha.6 • Published 7 years ago

streaming-http-request v1.0.0-alpha.6

Weekly downloads
3
License
UNLICENSED
Repository
github
Last release
7 years ago

streaming-http-request

Make HTTP requests for streams of data from the browser

Usage

import StreamingHttpRequest from 'streaming-http-request';
new StreamingHttpRequest(url);

Each instance of StreamingHttpRequest is an object similar to Node.js EventEmitter that emits the following events:

  • data - emitted with an object for each parsed JSON message streamed from the response
  • error - emitted each time the underlying XMLHttpRequest object or JSON.parse function call throws an error

A StreamingHttpRequest instance immediately begins emitting data after the first data event listener is added, and it stops emitting data after the last listener is removed.

Example usage with recompose.lifecycle:

lifecycle({
  componentWillMount() {
    this.request = new StreamingHttpRequest(url);
    this.request.addListener('data', this.props.handleData);
    this.request.addListener('error', this.props.handleError);
  },
  componentWillUnmount() {
    this.request.removeListener('data', this.props.handleData);
    this.request.removeListener('error', this.props.handleError);
  },
}),