gwt Defining and using your REST client


Example

You should already have your backend REST resource available. On the client side (GWT) your need to

  1. Add RestyGwt dependency to your project with maven

    <dependency>
        <groupId>org.fusesource.restygwt</groupId>
        <artifactId>restygwt</artifactId>
        <version>2.2.0</version>
    </dependency>
    
  2. Add the inheritance to your module file

    <inherits name="org.fusesource.restygwt.RestyGWT"/>
    
  3. Create your client interface

    public interface PizzaService extends RestService {
        @POST
        @Path("pizzaorders")
        public void order(PizzaOrder request, 
                          MethodCallback<OrderConfirmation> callback);
    }
    
  4. Use your client where you want in you app

    PizzaService service = GWT.create(PizzaService.class);
    service.order(order, new MethodCallback<OrderConfirmation>() {
        
    public void onSuccess(Method method, OrderConfirmation response) {
      //code your stuff here
    }
    
    public void onFailure(Method method, Throwable exception) {
      //code your stuff here
    });