Git Product home page Git Product logo

b's Introduction

/b

Persistant KeyValue storage


Some times you just need a quick and dirty data storage, something that just gives you a bucket to pour some data into.

This is that bucket.

Installing


Update the settings file with the values for your enviroment, in that file you'll also find the SQL for creating the database table.

Create/Upload/add/Edit and you'll have your own /b.

Saving


Saving is as simple as a GET request to the server. If an ID is supplied that post will be updated.

Remember that this method limits the amount of data transported to the max URL length, so try to keep it under 1855 characters in total.

Save (jQuery)

function saveData(key, data, id){
    var request = {
        key: key,
        data: JSON.stringify(data)
    };
    
    if(id)
        request.id = id;
    
    $.getJSON("/b", request)
    .fail(function(re){ 
        //Handle failures to save here
    })
    .done(function(re){
        //Handle successful save here
    })
}

If the save is successful you will get a JSON object back consisting of these keys:

  • type Response type (ie. "success")
  • info Action performed (ie. "inserted")
  • id The ID of the element effected

Save response example

{
    type: "success", 
    info: "inserted", 
    id: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr"
}

Loading


Loading is just as simple, just supply the key of the bucket and the ID of the data.

Load (jQuery)

function loadData(key, id){
    $.getJSON("/b",{
        key: key,
        id: id
    })
    .fail(function(re){ 
        //Handle load fail here
    })
    .done(function(re){
        //Handle successful loading here
        //Don't forgett to parse it if it's JSON
        //i.e. JSON.parse(re)
    })
}

Successfully loading data returns these keys:

  • type Response type (ie. "success")
  • info Action performed (ie. "loaded")
  • id The ID of the element effected
  • data The data saved (as a string)
  • created The time the ID was created

Load response example

{
    type: "success", 
    info: "loaded", 
    id: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr",
    data: '{"hello":"world"}', 
    created: "1970-01-01 00:00:00"
}

Errors


Not often but sometimes you go goof up, then the server will return an error. This happens when you don't send enough parameters, the wrong parameters or something else is wrong. This is what it can look like:

Error response example

{
    "type":"error",
    "info":"wrong parameters"
}  

Please note that all errors will be wrapped in a HTTP 500 response.

That's it. โ™ฅ

b's People

Contributors

pjotor avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.