JSONP-DB for Tilde Club

Hi my name is Chris, my home page is here.

I set up a thing so you can store/retrieve JSON on your page. Use it for whatever you want. This is a tweaked implementation of JSONP-DB-Redux.


Storing data

Note: adding the same object twice will result in two entries (with the same content) with two different keys.

Example:
http://tilde-club-db.appspot.com/put/buckets/myFoo/{"foo":"bar","baz":9}?callback=myFunction

Response:
myFunction('agNpZWRyDQsSB2NvbnRhY3QYAQw'); (item key is unique to this object)

Retrieve by item key

Example:
http://tilde-club-db.appspot.com/get/keys/agNpZWRyDQsSB2NvbnRhY3QYAQw?callback=myFunction

Response:
myFunction({"foo":"bar","baz":9});

Retrieve all items in a bucket

Example:
http://tilde-club-db.appspot.com/get/buckets/myFoo/?callback=myFunction

Response:
myFunction([{"foo":"bar","baz":9},{"foo":"bar2","baz":10}]);

Retrieve specific items by query (within a bucket)

Example
You pass an object - all fields will have to match:
http://tilde-club-db.appspot.com/get/kind/myFoo/?filter={"foo":"bar2"}&callback=myFunction

Response:
myFunction([{"foo":"bar2","baz":10}]);


Sample code

Storing data

var putData = function (data) {
  var jsonData = JSON.stringify(data)
  var jsonpURL = 'http://tilde-club-db.appspot.com/put/buckets/my-bucket/' + jsonData + '?callback=myPutCallback';
  var script = document.createElement('script');
  script.src = jsonpURL;
  document.head.appendChild(script);
};

var myPutCallback = function (id) {
  alert('Data stored with id: ' + id);
};

document.getElementById('button').onclick = function () {
  var text = document.getElementById('text').value.replace(/\"/g, '"'); // shrug emoji;
  putData({"myText":text});
  return false;
};

Retrieving data

var getData = function () {
  var jsonpURL = 'http://tilde-club-db.appspot.com/get/buckets/my-bucket/?callback=myGetCallback';
  var script = document.createElement('script');
  script.src = jsonpURL;
  document.head.appendChild(script);
};

var myGetCallback = function (data) {
  for (var i = 0; i < data.length; i++) {
    console.log(data[i]);
  }
};

getData();

How is the data kept private?

It super-duper isn't!

Closing thoughts