resty-gwt is a GWT generator for REST services and JSON encoded data transfer objects.
Pull request Compare This branch is 815 commits behind resty-gwt:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



RestyGWT is a GWT generator for REST services and JSON encoded data transfer objects.

Project Resources


  • Generates Async Restful JSON based service proxies
  • Java Object to JSON encoding/decoding
  • Easy to use REST API

REST Services

RestyGWT Rest Services allow you to define an asynchronous Service API which is then implemented via GWT deferred binding by a RestyGWT generator. See the following listing for an example:

public interface PizzaService extends RestService {
    public void order(PizzaOrder request, MethodCallback<OrderConfirmation> callback);

JAX-RS annotations are used to control how the methods interface map to HTTP requests. The interface methods MUST return void. Each method must declare at least one callback argument.
Methods can optionally declare one method argument before the callback to pass via the request body.

Java beans can be sent and received via JSON encoding/decoding. Here what the classes declarations look like for the PizzaOrder and OrderConfirmation in the previous example:

public class PizzaOrder {
    public String phone_number;
    public boolean delivery;
    public List<String> delivery_address = new ArrayList<String>(4);
    public List<Pizza> pizzas = new ArrayList<Pizza>(10);

public class OrderConfirmation {
    public long order_id;
    public PizzaOrder order;
    public double price;
    public Long ready_time;

The JSON encoding style is compatible with the default Jackson Data Binding. En example, PizzaOrder JSON representation would look like:

    "3434 Pinerun Ave.",
    "Wesley Chapel, FL 33734"
    {"quantity":1,"size":16,"crust":"thin","toppings":["extra cheese"]}

A GWT client creates an instance of the REST service and associate it with a HTTP resource URL as follows:

Resource resource = new Resource( GWT.getModuleBaseURL() + "pizza-service");

PizzaService service = GWT.create(PizzaService.class);

service.order(order, callback);


The RestyGWT REST API is handy when you don't want to go through the trouble of creating service interfaces.

The following example, will post a JSON request and receive a JSON response. It will set the HTTP Accept and Content-Type and X-HTTP-Method-Override header t o the expected values. It will also expect a HTTP 200 response code, otherwise it will consider request the request a failure.

Resource resource = new Resource( GWT.getModuleBaseURL() + "pizza-service");

JSONValue request = ... JsonCallback() {
    public void onSuccess(Method method, JSONValue response) {
    public void onFailure(Method method, Throwable exception) {
        Window.alert("Error: "+exception);

All the standard HTTP methods are supported:

  • resource.head()
  • resource.get()
  • resource.put()
  • resource.delete()

Calling one of the above methods, creates a Method object. You must create a new one for each HTTP request. The Method object uses fluent API for easy building of the request via method chaining. For example, to set the user id and password used in basic authentication you would:

method = resource.get().user("hiram").password("pass");

You can set the HTTP request body to a text, xml, or json value. Unless the content type is explicitly set on the method, the following methods will set the Content-Type header for you:

  • method.text(String data)
  • method.xml(Document data)
  • method.json(JSONValue data)

The Method object also allows you to set headers, a request timeout, and the expected 'successful' status code for the request.

Finally, once you are ready to send the http request, pick one of the following methods based on the expected content type of the result. Unless explicitly set on the method, the following methods will set the Accept header for you:

  • method.send(TextCallback callback)
  • method.send(JsonCallback callback)
  • method.send(XmlCallback callback)

The response to the HTTP request is supplied to the callback passed in the send method. Once the callback is invoked, the method.getRespose() method to get the GWT Response if your interested in things like the headers set on the response.

Using as a Maven Dependency

Just add the following dependency to your pom.xml


And also the following repository:

    <name>Hiram Chirino's Snapshot Repository</name>