Skip to content

faeldt/simple-get

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-get travis npm downloads

Simplest way to make http get requests

features

This module is designed to be the lightest possible wrapper on top of node.js http, but supporting:

  • follows redirects
  • automatically handles gzip/deflate responses
  • supports HTTPS
  • supports convenience url key so there's no need to use url.parse on the url when specifying options

All this in < 100 lines of code.

install

npm install simple-get

usage

var get = require('simple-get')

get('http://example.com', function (err, res) {
  if (err) throw err
  console.log(res.statusCode) // 200
  res.pipe(process.stdout) // `res` is a stream
})

A more complex example:

var get = require('simple-get')
var concat = require('concat-stream')

get({
  url: 'http://example.com',
  maxRedirects: 3, // default value is 10 
  
  // simple-get accepts all options that node.js `http` accepts
  // See: http://nodejs.org/api/http.html#http_http_request_options_callback
  headers: {
    'user-agent': 'my cool app'
  }
}, function (err, res) {
  if (err) throw err
  
  // All properties/methods from http.IncomingResponse are available,
  // even if a gunzip/inflate transform stream was returned.
  // See: http://nodejs.org/api/http.html#http_http_incomingmessage
  res.setTimeout(10000)
  console.log(res.headers)
  
  res.pipe(concat(function (data) {
    // `data` is the decoded response, after it's been gunzipped or inflated
    // (if applicable)
    console.log('got the response: ' + data)
  }))
  
})

license

MIT. Copyright (c) Feross Aboukhadijeh.

About

Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%