get-then

1.2.0 • Public • Published

get-then

Give a URL, Get a Buffer.
~50 lines of code!

var get = require('get-then')
 
get('https://api.github.com/users/williamkapke')
.then(JSON.parse)
.catch(String)
.then(console.log)

Need header data?

var get = require('get-then')
 
get('https://api.github.com/users/williamkapke')
.then(buffer => {
  console.log(buffer.statusCode, buffer.statusMessage)
  console.log(buffer.headers)
  return buffer;
})
.then(console.log)// prints the buffer

Other HTTP Methods

Ok, so you can do more then just GETs. It only added a few more lines of code.

The function returned can take 4 arguments: function (url, headers, data, method)
(only the 1st is required)

If data is specified:
• if it is a stream, it will be piped to the request. Otherwise... • it will be passed to JSON.stringify().
• it will set the Content-Length header.
• it will default to POST if method is not supplied.

User-Agent

A default User-Agent is specified as:

https://www.npmjs.com/package/get-then

To override this default:

var get = require('get-then')
get.agent = 'My Fancy Script'

License

MIT Copyright (c) William Kapke

Package Sidebar

Install

npm i get-then

Weekly Downloads

8

Version

1.2.0

License

MIT

Last publish

Collaborators

  • williamkapke