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
You can easily call a Restful web services using RestyGWT in your GWT application by creating proxy service interface:
import javax.ws.rs.POST;
...
public interface PizzaService extends RestService {
@POST
public void order(PizzaOrder request,
MethodCallback callback);
}
or when you don't want to go through the trouble of creating service interfaces:
Resource resource = new Resource( GWT.getModuleBaseURL() + "pizza-service");
JSONValue request = ...
resource.post().json(request).send(new JsonCallback() {
public void onSuccess(Method method, JSONValue response) {
System.out.println(response);
}
public void onFailure(Method method, Throwable exception) {
Window.alert("Error: "+exception);
}
});
It has also got nice API for encoding and decoding Java Object to JSON.