Drupal & Titanium create a node webservice Example

so you have Drupal web services , and you want to make a mobile app here is an idea to create a simple node in your app.js add some thing like...
make sure your rest server is using jason as responce , this is an example with no authentacation , so you need to give the right permissions in drupl :)

var button = Titanium.UI.createButton({
   title: 'Hello',
   top: 10,
   width: 100,
   height: 50
});
button.addEventListener('click',function(e)
{
   Titanium.API.info("You clicked the button");
   transmit();
});


function transmit(){
// if developing on local host .. get your network ip cmd ipconfig 
	var serverURL ='http://192.168.2.40/drupal-7.33/myend/node';
	
    var xhr=Titanium.Network.createHTTPClient();    
    xhr.open("POST", serverURL);
 
    xhr.onload = function(){
     //alert("responseText: " + this.responseText);
     if(this.status == '200'){
        alert('Transmission successful!');
        //if(this.readyState == 4){
        //  alert('Response = ' + response);
        //}else{
        //  alert('HTTP Ready State != 4');
        //}           
     }else{
        alert('Transmission failed. Try again later. ' + this.status + " " + this.response);
     }              
    };
 
    xhr.onerror = function(e){alert('Transmission error: ' + e.error);};
 
    xhr.setRequestHeader("Content-Type","application/json");

    var node = {"node":{
"type":"page",
"title":"This is my new title ",
"language":"und",
"body":{"und":{"0":{"value":"This is the body of my node"}}}
}};
 
    var obj = (node); 
   xhr.send(JSON.stringify(obj)); 
}


win1.add(button);

So that creates a node ,, to create a user try this one :)

var button2 = Titanium.UI.createButton({
   title: 'Create User Account',
   top: 10,
   width: 100,
   height: 50
});

button2.addEventListener('click',function(e)
{
   Titanium.API.info("You clicked the button 2");
   
   //https://www.drupal.org/node/1447020
  var theuser = {
       "name":"services_user_1",
        "pass":"password",
        "mail":"services_user_1@example.com"
   };
createuser(theuser , "http://192.168.2.40/drupal-7.33/myend/user/register");
});

function createuser(theuser , serverURL){
    var xhr=Titanium.Network.createHTTPClient();    
    xhr.open("POST", serverURL);
 
    xhr.onload = function(){
     //alert("responseText: " + this.responseText);
     if(this.status == '200'){
        alert('User Created  successful!');
        //if(this.readyState == 4){
        //  alert('Response = ' + response);
        //}else{
        //  alert('HTTP Ready State != 4');
        //}           
     }else{
        alert('user creation  failed. Try again later. ' + this.status + " " + this.response);
     }              
    };
 
    xhr.onerror = function(e){alert('Transmission error: ' + e.error);};
 
    xhr.setRequestHeader("Content-Type","application/json");
    var obj = (theuser); 
   xhr.send(JSON.stringify(obj)); 
 
};


win2.add(button2);
Category: