simple-get-stream
v1.0.2
Published
Simply wraps [simple-get][] and his methods to return Response stream instead of Request stream. Simple as `simpleGet.get(url).pipe(process.stdout)`
Downloads
119
Readme
simple-get-stream
Simply wraps simple-get and his methods to return Response stream instead of Request stream. Simple as
simpleGet.get(url).pipe(process.stdout)
Install
npm i simple-get-stream --save
Usage
For more use-cases see the tests
const simpleGetStream = require('simple-get-stream')
simpleGetStream
Request a page and return a response stream
Params
<opts>
{String|Object}: Url or options object, passed tosimple-get
.returns
{Stream}: Response stream instead of Request stream assimple-get
does.
Example
const request = require('simple-get-stream')
const stream = request('http://www.tunnckocore.tk')
stream.once('error', console.error)
stream.pipe(process.stdout) // => html content of the page
Advanced example
Showing use of
.post
method and getting the response, using through2
const through2 = require('through2')
const request = require('simple-get-stream')
const stream = request.post({
url: 'http://httpbin.org/post',
body: JSON.stringify({
foo: 'bar',
baz: 'qux'
})
})
stream.once('error', console.error)
stream.pipe(through2(function (buf) {
var res = buf.toString()
var data = JSON.parse(res)
console.log(data.json)
/* => {
foo: 'bar',
baz: 'qux'
} */
}))
Related
- github-base: Base methods for creating node.js apps that work with the GitHub… more | homepage
- npm-info: Base class for downloading data from the npm registry | homepage
- request-all: Performs a multiple requests and data from all pages are concatenated… more | homepage
- simple-get: Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate,… more | homepage
- simple-get-stream: Simply wraps
simple-get
and his methods to return Response stream instead… more | homepage - then-got: Promisified
simple-get
. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.