I/O primitives using promises
const io = require("io-promise");
io.fetch("http://www.example.org").then(function (res) {
return res.text();
})
io.fetch("http://www.example.com/object.json").then(function (res) {
return res.json();
})
io.post("http://www.example.org", {foo: "bar"} ).then(function (res) {
return res.text();
})
io.readJSON("myfile.json").then(function (data) {
do something with data;
})
io.readJSON("myfile.json").then(function (data) {
do something with data;
})
io.fetch("http://www.example.org", { delay: 2 } ).then(function (res) {
return res.text();
})
status
HTTP status code
url
URL requested
headers
Object will all of the headers from the HTTP response
text()
Returns the data as a string
json()
Returns the data as an object
io.monitor(); // active the monitoring
io.returns an array contains all of the url requested
Caching of fetch requests
var cache = new io.Cache("/tmp/");
cache.load("http://www.example.org").then(function (res) {
return res.text();
})