I\'m using GWT as web development framework. I need to access some REST services from my GWT client code. Also I need to parse JSON (or maybe XML) which is response format o
For this stuff, I find it easier to fall back to using GWT JSNI.
Eg, Calling a JSON service to get the users country code:
public static native void getCountryCode(Loaded countryCode) /*-{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var jsonObj = JSON.parse(xhttp.responseText);
countryCode.@mypackage.Loaded::data(*)(jsonObj.country_code);
}
};
xhttp.open("GET", "https://api.ipdata.co/", true);
xhttp.send();
}-*/;
Where "Loaded" is just:
package mypackage;
public interface Loaded {
public void data(T data);
}