npm.io
1.0.2 • Published 10 years ago

simple-get-stream

Licence
MIT
Version
1.0.2
Deps
2
Vulns
0
Weekly
0
Stars
3

simple-get-stream npmjs.com The MIT License

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')
simpleGetStream

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'
  } */
}))

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.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

Keywords