forked from Supositware/Haha-Yes
2.1 KiB
2.1 KiB
node-miniget
A small http(s) GET library with redirects, retries, reconnects, concatenating or streaming, and no dependencies. This keeps filesize small for potential browser use.
Usage
Concatenates a response
const miniget = require('miniget');
miniget('http://mywebsite.com', (err, body) => {
console.log('webpage contents: ', body);
}));
Request can be streamed right away
miniget('http://api.mywebsite.com/v1/messages.json')
.pipe(someWritableStream());
API
miniget(url, [options], [callback(err, body)])
Makes a GET request. options
can have any properties from the http.request()
function, in addition to
maxRedirects
- Default is2
.maxRetries
- Number of times to retry the request if there is a 500 or connection error. Default is1
.maxReconnects
- During a big download, if there is a disconnect, miniget can try to reconnect and continue the download where it left off. Defaults to0
.backoff
- An object withinc
andmax
used to calculate how long to wait to retry a request. Defaults to{ inc: 100, max: 10000 }
.highWaterMark
- Amount of data to buffer when in stream mode.transform
- Use this to add additional features. Called with the object thathttp.get()
orhttps.get()
would be called with. Must return a transformed object.
If callback
is given, will concatenate the response, and call callback
with a possible error, and the response body.
Miniget returns a readable stream if callback
is not given, errors will then be emitted on the stream. Returned stream also contains an .abort()
method.
Install
npm install miniget
Tests
Tests are written with mocha
npm test