supercommando440
supercommando440

Reputation: 59

gwt-rpc vs rest... is it really one or the other?

I have a GWT client using GWT-RPC to make calls to my REST service. Why do some of these comments pit GWT-RPC against REST, as if you have to choose one or the other? I'm using BOTH... GWT-RPC on the client, which hits a REST service. I want to use an alternative and ditch GWT-RPC. Why? It's SLOW (compared to my Flex client that hits same service). I checked out RestyGWT but it's great documentations (sarcasm) makes it sound like I need to build a RestyGWT SERVICE that my RestyGWT client can hit. Geez, NO thanks. My service is done. I really don't want to touch it. So it sound like one possible alternative is to generate a client lib from my service and use it in my GWT client along with RequestBuilder to handle encoding/decoding of JSON to java objects (and hopefully get improved performance). If that doesn't cut it, the next alternative is to ditch GWT altogether.

Upvotes: 1

Views: 2327

Answers (2)

GwtQuery autobeans and ajax, is a light-weight client alternative to gwt-autobeans and gwt-requestbuilder (as well as to other json solutions like erray, resty) for using REST.

It is based on the jquery api, but it has been entirely rewritten in java, taking advantage of the jquery simplicity and the gwt performance.

IMO, it is one of the best options to consume 3party services (xml, json, jsonp, etc). It provides an easy syntax, and many features like promises (available on 1.4.0-SNAPSHOT) etc.

This is an example of how to consume a json rest service and map it to a java bean. As you can see it is simple, and performance is really good.

// Let GQuery generator wrap json to java
// there is a generator for xml services as well.
public static interface MyBean extends JsonBuilder {
  long getId();
  String[] getTags();
  String getTitle();
}

public void onModuleLoad() {
  // Configure a JSON Ajax request
  Settings rq = Ajax.createSettings()
    .setUrl("rest_service.js")
    .setType("post") // options: get post put delete head
    .setDataType("json") // send and read json data
    .setData($$("foo: bar")); // Your JavaScriptObject

  // last GQuery Ajax returns a chainable Promise which makes the code more
  // readable instead of dealing with callback parameters
  Ajax.ajax(rq)
    .done(new Function() {
      public void f() {
        // You can inspect arguments with this
        System.out.println(dumpArguments());

        // Create the bean, and wrap the json object read
        MyBean b = GWT.create(MyBean.class);
        b.load(arguments(0));

        // toString in JsonBuilder returns the json string
        System.out.println(b.toString());
      }
    })
    .fail(new Function() {
      public void f() {

      }
    });
}

Upvotes: 1

Thomas Broyer
Thomas Broyer

Reputation: 64541

Have a look at Errai JAX-RS to build "REST" clients (almost) as easily as with GWT-RPC.

Upvotes: 4

Related Questions