Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Retrieving todo items from Realtime Cloud Storage using the REST API from Appcelerator Titanium. This sample can be used with http://storage-public.realtime.co/samples/todo-lbl/index.html#/
//UI
Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({
backgroundColor:'#fff'
});
var label1 = Titanium.UI.createLabel({
color:'#777',
text:'Connecting to Realtime Storage...',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win1.add(label1);
win1.open();
//Connection
var body = {
table: "todoTable",
key: {
primary: "storage-demo"
},
searchForward: true,
applicationKey: "2Ze1dz",
authenticationToken: "TodoRealtimeStorage"
};
var hClient = Ti.Network.createHTTPClient({
onload : function() {
label1.text = 'Items:\n\n'+JSON.parse(this.responseText).data.items.map(function(i){return JSON.stringify(i);}).join('\n\n');
},
onerror : function(e) {
label1.text('An error has occured... ' + e);
},
timeout : 5000 // in milliseconds
});
hClient.open("POST", 'https://storage-backend-prd-useast1.realtime.co/queryItems');
hClient.setRequestHeader('Content-Type', 'application/json');
hClient.send(JSON.stringify(body));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment