Created
April 20, 2020 03:30
-
-
Save ifyour/749c422d1eb2710e86f4448abbca6e4f to your computer and use it in GitHub Desktop.
JSONBase
This file contains hidden or 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
| import fetch from "node-fetch"; | |
| const api = "https://jsonbase.com/"; | |
| export default class Bucket { | |
| constructor(name) { | |
| this.name = name; | |
| } | |
| async get(key) { | |
| let data = await fetch(api + this.name + "/" + key).then(x => x.json()); | |
| return data; | |
| } | |
| async put(key, value) { | |
| let data = await fetch(api + this.name + "/" + key, { | |
| method: "PUT", | |
| body: JSON.stringify(value), | |
| headers: { "content-type": "application/json" } | |
| }).then(x => x.json()); | |
| return data; | |
| } | |
| } | |
| // Tests | |
| // | |
| // let demo_bucket = new Bucket('demo_bucket'); | |
| // demo_bucket.get('joe') | |
| // .then(data => console.log(data)) | |
| // demo_bucket.put('mike', {hello: 'mike'}) | |
| // .then(data => console.log(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment