Last active
April 6, 2021 15:07
-
-
Save crazy4groovy/000b471e499fedd1f42495e3aebb3224 to your computer and use it in GitHub Desktop.
APIs for online JSON datastorage services (JavaScript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://jsonblob.com/ | |
fetch = fetch || require('cross-fetch') | |
async function jsonblob( | |
json /* : Object */, | |
method /* : string */, | |
id /* : string */ | |
) /* : Promise */ { | |
const isUpsert = method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'DELETE' | |
const options = { | |
method, | |
headers: { "Content-Type": "application/json", "Accept": "application/json" }, | |
body: isUpsert ? JSON.stringify(json) : undefined | |
} | |
const uri = `https://jsonblob.com/api/jsonBlob${id ? `/${id}` : ''}` | |
return fetch(uri, options) | |
.then(resp => resp.json()) | |
.then(data => ({ | |
uri, | |
id: id || data.uri.match(/jsonBlob\/(.*)/)[1], | |
data | |
})) | |
.catch(err => console.error('ERR jsonblob:', err) || Promise.reject(err)) | |
} | |
try { module.exports = jsonblob } catch (ignore) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://jsonbox.io/ | |
fetch = fetch || require('cross-fetch') | |
async function jsonbox( | |
json /* : Object */, | |
method /* : string */, | |
bucket /* : string */, | |
id /* : string */, | |
) /* : Promise */ { | |
const isUpsert = | |
method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'DELETE' | |
const options = { | |
method, | |
headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, | |
body: isUpsert ? JSON.stringify(json) : undefined, | |
} | |
const uri = `https://jsonbox.io/${bucket}${id ? `/${id}` : ''}` | |
return fetch(uri, options) | |
.then(resp => resp.json()) | |
.then(data => ({ | |
uri, | |
id: id || data._id, | |
data, | |
})) | |
.catch(err => console.error('ERR jsonbox:', err) || Promise.reject(err)) | |
} | |
try { module.exports = jsonbox } catch (ignore) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://jsonstore.io/ | |
// Note: EXPIRED! See https://db.neelr.dev/ (https://github.com/bluzi/jsonstore/issues/74) - code below may need tweaking! | |
fetch = fetch || require('node-fetch') | |
function jsonstoreio(username /* : string */, path /* : string */, method /* : string */, body /* : ?string */) /* : Promise */ { | |
const key = username + 'f83c453cec7234be5bb130fcee5b573bc5fa2573dd647ec54b51075d258c3840'.slice(username.length) | |
const isUPSERT = method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'DELETE' | |
const params = (!isUPSERT && body) | |
? Object.keys(body) | |
.map(key => `${key}=${encodeURIComponent(body[key])}`) | |
.join('&') | |
: '' | |
return fetch( | |
`https://www.jsonstore.io/${key}/${path}?${params}`, { | |
headers: { 'Content-type': 'application/json' }, | |
method, | |
body: isUPSERT ? JSON.stringify(body) : undefined, | |
}).then(r => r.json()); | |
} | |
/* | |
// Send POST requests to store data, PUT and DELETE requests to modify or delete data, and GET requests to fetch data. | |
// Note: GET supports params: orderKey (orderByChild); filterValue and valueType | |
// https://github.com/bluzi/jsonstore/blob/master/api/routes.js#L23 | |
// https://github.com/bluzi/jsonstore/blob/master/api/database.js#L41 | |
await jsonstoreio('11steveo11', 'users/1', 'POST', { age: 1, nums: 4 }) | |
await jsonstoreio('11steveo11', 'users/99', 'POST', { age: 99, nums: 3 }) | |
await jsonstoreio('11steveo11', 'users/2', 'POST', { age: 2, nums: 2 }) | |
await jsonstoreio('11steveo11', 'users/2/age', 'PUT', 22) | |
await jsonstoreio('11steveo11', 'users', 'GET') | |
await jsonstoreio('11steveo11', 'users', 'GET', { orderKey: 'nums' }) | |
await jsonstoreio('11steveo11', 'users', 'GET', { orderKey: 'age', filterValue: 1, valueType: 'number' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://kvdb.io/ | |
// official client: https://github.com/pilvy/kvdb.io-commonjs | |
// see: https://kvdb.io/pricing | |
// see: https://kvdb.io/docs/api/#buckets | |
fetch = fetch || require('cross-fetch') | |
async function kvdb( | |
json /* : any */, // key value -- note: https://kvdb.io/docs/api/#update-a-key-counter | |
method /* : string */, // GET, POST, PATCH, DELETE | |
bucket /* : string */, // eg. 7gQXr8K98yrj5h1kceKhfA | |
id /* : string */, // key name | |
ttl: /* : number */ // in seconds | |
) /* : Promise */ { | |
const isUpsert = | |
method.toUpperCase() === 'PATCH' && method.toUpperCase() === 'POST' | |
const options = { | |
method, | |
headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, | |
body: isUpsert ? JSON.stringify(json) : undefined, | |
} | |
const uri = `https://kvdb.io/${bucket}/${id}${ttl ? `?ttl=${Number(ttl)}` : ''}` | |
return fetch(uri, options) | |
.then(resp => resp.json()) | |
.then(data => ({ | |
uri, | |
id, | |
data: data || json, | |
})) | |
.catch(err => console.error('ERR kvdb:', err) || Promise.reject(err)) | |
} | |
try { module.exports = kvdb } catch (ignore) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://textdb.dev/ | |
fetch = fetch || require('cross-fetch') | |
async function jsonblob( | |
json /* : Object */, | |
method /* : string */, | |
id /* : string */ | |
) /* : Promise */ { | |
const isUpsert = method.toUpperCase() !== 'GET' && method.toUpperCase() !== 'DELETE' | |
const options = { | |
method, | |
headers: { "Content-Type": "application/json", "Accept": "application/json" }, | |
body: isUpsert ? JSON.stringify(json) : undefined | |
} | |
const uri = `https://textdb.dev/api/data/${id}` | |
return fetch(uri, options) | |
.then(resp => resp.json()) | |
.then(data => ({ uri, data })) | |
.catch(err => console.error('ERR textdb:', err) || Promise.reject(err)) | |
} | |
try { module.exports = jsonblob } catch (ignore) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment