How to call RESTFUL services from GWT?

前端 未结 6 1176
小蘑菇
小蘑菇 2020-12-08 10:59

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

6条回答
  •  爱一瞬间的悲伤
    2020-12-08 11:19

    RequestBuilder is a low-level approach to make HTTP requests.

    You can resort to a higher level approach working with Turbo GWT HTTP, a convenient API for managing client-server communication and performing requests fluently.

    It fits better the REST style communication. Consider the following example:

    Request request = requestor.request(Void.class, Book.class)
            .path("server").segment("books").segment(1)
            .get(new AsyncCallback() {
                @Override
                public void onFailure(Throwable caught) {
    
                }
    
                @Override
                public void onSuccess(Book result) {
                    Window.alert("My book title: " + result.getTitle());
                }
    });
    

    There's no need to map your REST services before calling them (which is conceptually required for RPC communication, but not for REST). You can just consume your services on demand.

提交回复
热议问题