Skip to content

tunnckoCore/simple-get-stream

Repository files navigation

Simply wraps simple-get and his methods to return Response stream instead of Request stream. Simple as simpleGet.get(url).pipe(process.stdout)

code climate standard code style travis build status coverage status dependency status

Install

npm i simple-get-stream --save

Usage

For more use-cases see the tests

const simpleGetStream = require('simple-get-stream')

Request a page and return a response stream

Params

  • <opts> {String|Object}: Url or options object, passed to simple-get.
  • returns {Stream}: Response stream instead of Request stream as simple-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

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.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

Simply wraps `simple-get` and his methods to return Response stream instead of Request stream. For example `simpleGet.get(url).pipe(process.stdout)`.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published