Hello Team,
Please find below a sample code to use voltmx.net library to perform services calls directly from an Iris application to JSON / XML backend services.
serviceCall : function () { voltmx.print ("Entering into serviceCall"); //XML service URL var url = 'https://rss.nytimes.com/services/xml/rss/nyt/world.xml'; //JSON service URL //var url = 'https://api.openweathermap.org/data/2.5/weather?q=Seattle&appid=7fd82bbcddf7fca658e257db4c6577f3';var request = new voltmx.net.HttpRequest (); request.onReadyStateChange = onReadyStateChange; //Use this responseType when expecting to receive a XML as response request.responseType = constants.HTTP_RESPONSE_TYPE_DOCUMENT; //Use this responseType when expecting to receive a JSON as response //request.responseType = constants.HTTP_RESPONSE_TYPE_JSON; request.open (constants.HTTP_METHOD_GET, url, true); //Use this Content-Type when interacting with a XML backend service request.setRequestHeader ("Content-Type", 'application/xml'); //Use this Content-Type when interacting with a JSON backend service //request.setRequestHeader ("Content-Type", 'application/json'); request.send (); voltmx.print ("Exiting out of serviceCall"); function onReadyStateChange () { voltmx.print ("Entering into onReadyStateChange"); if (this.readyState === constants.HTTP_READY_STATE_DONE) { voltmx.print('readyState ::' + this.readyState); voltmx.print('responseType ::' + this.responseType); //Use this code to print the XML response received from backend service voltmx.print('response ::' + new XMLSerializer().serializeToString(this.response.documentElement)); //Use this code to print the JSON response received from backend service //voltmx.print('response ::' + JSON.stringify(this.response)); //Use this code to alert the XML response received from backend service alert("Response : "+new XMLSerializer().serializeToString(this.response.documentElement)); //Use this code to alert the JSON response received from backend service //alert("Response : "+JSON.stringify(this.response)); } voltmx.print ("Exiting out of onReadyStateChange"); }
}
Thanks and Regards,
Venkata Raju Bankapalli