NodeJS module for storing (public) JSON via myjson.com
fetch = fecth || require('cross-fetch')
function myjson(json /* : Object */, id /* : string */) /* : Promise */ {
const options = {
method: id ? 'PUT' : 'POST',
headers: { "Content-Type": "application/json; charset=utf-8" },
body: JSON.stringify(json)
}
const uri = `https://api.myjson.com/bins${id ? `/${id}` : ''}`
return fetch(uri, options)
.then(resp => resp.json())
.then(data => ({
uri,
id: id || data.uri.match(/bins\/(.*)/)[1]
// data
}))
.catch(err => console.error('ERR myjson:', err) || Promise.reject(err))
}
try { module.exports = myjson } catch (ignore) {}