Version: 0.9.1 (beta)
Supported client libraries: jQuery, AngularJS, Python
Service connector constructor. Takes all options to connect to the service.
Parameter
User.token()
to authenticate the user. Browser based applications
can also call User.signin()
to retrieve the token as cookie to be handled automatically by the browser.See Endpoints for API calls for all supported options.
var storage = new nive.DataStore({name:"mystorage"}); storage.getItem({key:'key1'}) .done(function(data, message, jqXHR) { console.log(data); } );
Returns the stored item including value and timestamp for the key.
Parameter
Returns
Status codes
nive.DataStore({name:"mystorage"}) .getItem({key: "key1"}) .done(function (data, message, xhr) { // receive the result e.g. // {key: "key1", value: "value1", timestamp: 1234567.89, id: 1234567890} var value = data.value; });
GET http://mydomain.nive.io/mystorage/api/getItem?key=key1 => {"key": "key1", "value": "value1"}
Creates a single item or a set of items as batch. Unlike DataStore.setItem()
the function fails if
one of the keys already exists. Use this function to make sure existing items will not be
replaced accidentally.
Keys and values must match validation rules defined in the backend. Otherwise the function will throw and error.
Parameter
Returns
Status codes
var newitems = [{key: "key1", value: "value1"}, {key: "key2", value: 1234}]; nive.DataStore({name:"mystorage"}) .newItem({items: newitems}) .done(function (data, message, xhr) { // success: items have been stored var number_stored = data.result; }) .fail(function (jqXHR, message, error) { // error: something went wrong // handle message });
POST http://mydomain.nive.io/mystorage/api/newItem Content-Type: application/json Body: {"items": [{"key": "key1", "value": "value1"}, {"key": "key2", "value": 1234}]} => {"result": 2}
Store a set of items as batch. Creates or replaces items based on their keys. Use DataStore.newItem()
instead if
you want to make sure existing items will not be replaced.
Keys and values must match validation rules defined in the backend. Otherwise the function will throw and error.
Parameter
Returns
Status codes
var newItem = {key: 'key1', value: 'value1'}; nive.DataStore({name:"mystorage"}) .setItem({items: newItem}) .done(function (data, message, xhr) { // success: items have been stored var number_stored = data.result; }) .fail(function (jqXHR, message, error) { // error: something went wrong // handle message }); // batch example var newItems = [{key: 'key1', value: 'value1'}, {key: 'key2', value: 1234}]; nive.DataStore({name:"mystorage"}) .setItem({items: newItems}) .done(function (data, message, xhr) { // success: items have been stored var number_stored = data.result; }) .fail(function (jqXHR, message, error) { // error: something went wrong // handle message });
POST http://mydomain.nive.io/mystorage/api/setItem Content-Type: application/json Body: {"key": "key1", "value": "value1"} => {"result": 1}
Delete one or more items.
Request parameter
Returns
Status codes
nive.DataStore({name:"mystorage"}) .removeItem({key: "key1"}) .done(function (data, message, xhr) { // success: item has been deleted if data.result is 1. number_deleted = data.result; });
POST http://mydomain.nive.io/mystorage/api/removeItem Content-Type: application/json Body: {"key": "key1"} => {"result": 1}
Returns a list of batched items for a single or multiple keys.
Parameter
Returns
Status codes
nive.DataStore({name: "mystorage"}) .list({key: ["key1", "key2"], order: "<", start: 0, size: 20}) .done(function (data, message, xhr) { // receive the result // e.g. {items: [{key: "key1", value: "value1"},...], // start: 0, size: 20, total: 32} var value1 = result.items[0].value; });
GET http://mydomain.nive.io/mystorage/api/list?key=key1&start=0&size=20 => {"items": [{"key": "key1", "value": "value1"}, ...], "start": 0, "size": 20, "total": 32}
Returns a list of existing keys.
Parameter
Returns
Status codes
nive.DataStore({name:"mystorage"}) .keys({order: "<", start: 0, size: 20}) .done(function (data, message, xhr) { // receive the result // e.g. {keys: ["key1", "key2"], start: 0, size: 20, total: 32} var key1 = result.keys[0]; });
POST http://mydomain.nive.io/mystorage/api/keys Content-Type: application/json Body: {"start": 0, "size": 20} => {"keys": ["key1", "key2"], "start": 0, "size": 20, "total": 32}
Checks whether or not the current user has the given permission(s).
Parameter
Return values
Status codes
nive.DataStore({name: "mystorage"}) .allowed({permission: "list"}) .done(function (data, message, xhr) { // data = {list:false, result:false} if(!data.result) $('#message').text('You are not allowed to list items.'); }); // or nive.DataStore({name: "mystorage"}) .allowed({permission: ["list","keys"]}) .done(function (data, message, xhr) { // data = {list:false, keys:true, result:false} if(data.keys) $('#message').text('You are allowed to query for keys.'); });
POST http://mydomain.nive.io/mystorage/api/allowed Content-Type: application/json {"permission":"list"} => {"result": false, "list": false}
Note
Administration function!
Retrieve all permissions and assigned groups of this service. The result contains a list of permission and groups items.
[
{permission: "newItem", groups: ["sys:noone"]},
{permission: "setItem", groups: ["sys:everyone"]},
...
]
Return values
The function returns a permission:name, groups:list item for each permission. [{permission:name, groups:list}, ...]
Status codes
nive.DataStore({name: "mystorage"}) .getPermissions() .done(function (data, message, xhr) { // data is a list of permission, group items // [ // {permission: "newItem", groups: ["sys:noone"]}, // {permission: "setItem", groups: ["sys:everyone"]}, // ... // ] });
POST http://mydomain.nive.io/mystorage/api/getPermissions Content-Type: application/json {} => [ {permission: "newItem", groups: ["sys:noone"]}, {permission: "setItem", groups: ["sys:everyone"]}, ... ]
Note
Administration function!
Update a single or multiple service permissions. Each permission to be updated must include the name, one or multiple groups and a action: ‘add’ (default), ‘replace’, ‘revoke’.
[
{permission: "newItem", groups: ["sys:noone"], action: "replace"},
{permission: "setItem", groups: ["sys:everyone"], action: "revoke"},
...
]
Actions
Parameter
for each permission
Return values
Status codes
var permissions = [ {permission: "newItem", groups: ["sys:everyone"], action: "revoke"}, {permission: "setItem", groups: ["sys:noone"], action: "replace"}, ]; nive.DataStore({name: "mystorage"}) .setPermissions(permissions) .done(function (data, message, xhr) { if(data.result) $('#message').text('Permissions have been updated.'); });
POST http://mydomain.nive.io/mystorage/api/setPermissions Content-Type: application/json { permissions: [ {permission: "newItem", groups: ["sys:everyone"], action: "revoke"}, {permission: "setItem", groups: ["sys:noone"], action: "replace"}, ]} => { result: true }
Retrieve the owner of a item referenced by key or id. This function returns a list of all matching items.
Parameter
Return values
Status codes
nive.DataStore({name: "mystorage"}) .getOwner({key: "key1"}) .done(function (data, message, xhr) { var owner; if(data.items) owner = data.items[0].owner; });
POST http://mydomain.nive.io/mystorage/api/setPermissions Content-Type: application/json { key: "key1" } => { items: [{key: "key1", owner: "the-user", id: 1234567890}] }
Change the owner of one or multiple items.
Parameter
Return values
Status codes
nive.DataStore({name: "mystorage"}) .setOwner({newOwner: "new-user", key: "key1"}) .done(function (data, message, xhr) { // data.success contains infos about the updated item e.g. // [[0, "key1", 1234567890, "new-user", 1234567.89] if(data.result) $('#message').text('The owner has been updated.'); });
POST http://mydomain.nive.io/mystorage/api/setOwner Content-Type: application/json { newOwner: "new-user", key: "key1" } => { result: 1, success: [[0, "key1", 1234567890, "new-user", 1234567.89]] }
Simple test and health check function.
Parameter
Return values
nive.DataStore().ping() .done(function (data, message, xhr) { $('#message').text('Is alive!'); });
GET http://mydomain.nive.io/mystorage/api/ping Content-Type: application/json {"active": true} => {"result": 1}