Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/plehegar/io-promise
I/O primitives using promises
https://github.com/plehegar/io-promise
Last synced: 15 days ago
JSON representation
I/O primitives using promises
- Host: GitHub
- URL: https://github.com/plehegar/io-promise
- Owner: plehegar
- License: mit
- Created: 2018-05-09T18:44:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T16:35:27.000Z (over 2 years ago)
- Last Synced: 2024-11-30T04:24:05.622Z (about 1 month ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# io-promise
I/O primitives using promises
```js
const io = require("io-promise");
```## Fetch support
```js
io.fetch("http://www.example.org").then(function (res) {
return res.text();
})
``````js
io.fetch("http://www.example.com/object.json").then(function (res) {
return res.json();
})
``````js
io.post("http://www.example.org", {foo: "bar"} ).then(function (res) {
return res.text();
})
```## File API support
```js
io.readJSON("myfile.json").then(function (data) {
do something with data;
})
``````js
io.readJSON("myfile.json").then(function (data) {
do something with data;
})
``````js
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
```js
io.monitor(); // active the monitoring
io.returns an array contains all of the url requested
```## Caching
Caching of fetch requests
```js
var cache = new io.Cache("/tmp/");
cache.load("http://www.example.org").then(function (res) {
return res.text();
})
```