Zero dependency, native promise based HTTP/HTTPS client for Node.js 4+.
$ npm install tiny-http-client -save
This client is primarily promise style wrapper around Node.js's HTTP library. Therefore,
all options supported by HTTP's request are supported. However, to simplify verbosity,
you can pass an initial set of options to the TinyHttpClient
constructor and they will be
applied on any request made using this object.
const httpClient = new TinyHttpClient({
protocol: 'https:', // set the default protocol
hostname: 'api.github.com', // set the default host
headers: { // set the default request headers
'Accept': 'application/json'
}
});
HTTP GET requests will internally buffer the body and return it once the promise resolves.
client.get({path: '/users/foo4u'})
.then(JSON.parse)
.then((response) => {
console.log(response.body);
});
.catch((err) => {
console.log(err);
});
HTTP HEAD requests will return a promise resolving response headers if the request is successful.
client.head({path: '/users/foo4u'})
.then((headers) => {
console.log(headers);
});
.catch((err) => {
console.log(err);
});
Found a bug or want add a feature? Please create an issue or send a pull request.
Apache 2.0