1.0.3 • Published 4 years ago
io-promise v1.0.3
io-promise
I/O primitives using promises
const io = require("io-promise");Fetch support
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();
})File API support
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();
})Response object
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
Monitoring
io.monitor(); // active the monitoring
io.returns an array contains all of the url requestedCaching
Caching of fetch requests
var cache = new io.Cache("/tmp/");
cache.load("http://www.example.org").then(function (res) {
return res.text();
})