JSONbin-update.js

//api.jsonbin.io/b/5b853513d6fe677c48d1b729 const JSONbin = (function () { const Config = { 'API_ROOT': 'https://api.jsonbin.io/b', 'BIN_ID': '5b85380b3ffac56f4bd5f772', }; // Update Bin const update = function (data) { data = JSON.stringify (data); return new Promise (function (resolve, reject) { let req = new XMLHttpRequest (); req.withCredentials = false; req.open ('PUT', `${Config.API_ROOT}/${Config.BIN_ID}`, true); req.setRequestHeader ('Content-type', 'application/json'); req.onreadystatechange = function () { if (req.readyState == XMLHttpRequest.DONE) { if (req.status == 200) { resolve (req.responseText); } else { reject (Error (req.statusText)); } } }; req.onerror = function () { reject (Error ('Network Error')); }; req.send (data); }); }; return { 'update': update, } })(); let newData = { "sample": "hello world ;)", "timestamp": new Date().getTime() }; JSONbin.update (newData).then ( function (results) { let response = JSON.parse (results); console.info ('success', response); window.open (`https://api.jsonbin.io/b/${response.parentId}/${response.version}`); }, function (results) { console.error ('error', results); }, );

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.