Socket
Socket
Sign inDemoInstall

stream-http

Package Overview
Dependencies
Maintainers
2
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


Version published
Weekly downloads
8.1M
decreased by-0.89%
Maintainers
2
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 26 Mar 2016

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