Although now I am not getting error as I removed the access to request object in function body, but still the response is not what I was expecting. When I call the same function over REST/HTTP, response returns all the countries data as shown below.
{"result":[{"@type":"d","@rid":"#14:0","@version":15,"@class":"MasterCountry","name":"Afghanistan","code":"AF","resetFlag":true}, {"@type":"d","@rid":"#14:1","@version":2,"@class":"MasterCountry","name":"\u00c5land Islands","code":"AX","resetFlag":true}, {"@type":"d","@rid":"#14:2","@version":2,"@class":"MasterCountry","name":"Albania","code":"AL","resetFlag":true}, {"@type":"d","@rid":"#14:3","@version":2,"@class":"MasterCountry","name":"Algeria","code":"DZ","resetFlag":true}, {"@type":"d","@rid":"#14:4","@version":2,"@class":"MasterCountry","name":"American Samoa","code":"AS","resetFlag":true}, {"@type":"d","@rid":"#14:5","@version":2,"@class":"MasterCountry","name":"AndorrA","code":"AD","resetFlag":true}, {"@type":"d","@rid":"#14:6","@version":2,"@class":"MasterCountry","name":"Angola","code":"AO","resetFlag":true}, {"@type":"d","@rid":"#14:7","@version":2,"@class":"MasterCountry","name":"Anguilla","code":"AI","resetFlag":true}, {"@type":"d","@rid":"#14:8","@version":2,"@class":"MasterCountry","name":"Antarctica","code":"AQ","resetFlag":true}, {"@type":"d","@rid":"#14:9","@version":2,"@class":"MasterCountry","name":"Antigua and Barbuda","code":"AG","resetFlag":true},
....
....
....
....
]}