phin
Ultra-simple, lightweight, dependency-free Node.JS HTTP request client (with util.promisify support)
Full documentation | GitHub | NPM
Simple Usage
For a simple GET request.
var p = require("phin");
p("https://www.ony.io", (err, res) => {
if (!err) console.log(res.body);
});
Installation
npm install phin
Demonstrations
GET request with added headers
p({
"url": "https://ony.io",
"headers": {
"User-Agent": "phin"
}
});
POST request with data
p({
"url": "https://ony.io",
"method": "POST",
"port": 8080,
"data": {
"name": "John Doe",
"someKey": "someValue"
},
"headers": {
"Content-Type" : "application/json" // or x/www-url-form-encoded if you want "data" encoded as a query string
}
}, (err, res) => {
if (!err) console.log("Sent data!");
});
GET request with authorization using auth
option
p({
"url": "https://ony.io:8080",
"auth": "ethan:letmein"
}, (err, res) => {
if (!err) console.log(res.body);
});
GET request with authorization through url
p({
"url": "https://ethan:letmein@ony.io:8080"
}, (err, res) => {
if (!err) console.log(res.body);
});
Documentation
Note that phin
has util.promisify
support.