Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-http

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-http

Streaming http in the browser

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.1M
increased by9.83%
Maintainers
1
Weekly downloads
 
Created

What is stream-http?

The stream-http npm package is designed to provide a streaming HTTP client for browser-based applications that mimics node's native http module, allowing for code that uses http to be more easily ported to the browser.

What are stream-http's main functionalities?

HTTP GET request

This feature allows you to perform an HTTP GET request and stream the response data as it is received.

const http = require('stream-http');

http.get('http://example.com', function (response) {
  response.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

HTTP request with options

This feature allows you to perform an HTTP request with custom options such as method, path, and headers, and to send data in the body of the request.

const http = require('stream-http');

const options = {
  method: 'POST',
  path: '/submit',
  headers: {'Content-Type': 'application/json'}
};

const req = http.request(options, function (response) {
  console.log('STATUS: ' + response.statusCode);
  response.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

req.write(JSON.stringify({ key: 'value' }));
req.end();

Handling request errors

This feature demonstrates how to handle errors that may occur during an HTTP request.

const http = require('stream-http');

http.get('http://example.com', function (response) {
  response.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
}).on('error', function (e) {
  console.error('Request failed: ' + e.message);
});

Other packages similar to stream-http

Keywords

FAQs

Package last updated on 16 Sep 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc