0
votes

I need to override the buildUrl method of rest proxy in Sencha Touch 2. The rest GET request will be like that:

url:'https://api.abc.com/user/{username}/{password}

Where and what should I change to achieve this goal?

and how should I pass the two parameters from controller? [I would like to pass username and password from login controller]

Can anyone please help me? Thanks

2

2 Answers

2
votes

This is how I have overridden buildUrl for my custom proxy, you can do similar thing:

Ext.define('MyApp.proxy.MyAjaxProxy', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.myajaxproxy',
buildUrl: function(request) {
    var me      = this,
        url     = me.callParent(arguments);
    if(!Ext.isEmpty(Helper.apiToken)){
        url = Ext.urlAppend(url, "token="+Helper.apiToken);
    }
    return url;
}
});

You can pass username & password in constructor from login controller like this:

var myProxy = Ext.create('MyApp.proxy.MyAjaxProxy', {
  username : "[email protected]",
  password : "mypassword"
});

and then in buildUrl method you should be able to access these like this this.config.username

-1
votes

Check out this url. It covers everything