Difference Between org.restlet.Client and org.restlet.resource.ClientResource

793 Views Asked by At

What are the main differences between org.restlet.Client and org.restlet.resource.ClientResource?

I've seen the classes used semi-interchangeably, so I'm mainly just looking for a general rule for when one should be used over the other.

1

There are 1 best solutions below

0
On BEST ANSWER

org.restlet.Client is the low-level API to execute REST requests with Restlet. org.restlet.resource.ClientResource internally uses this class to actually access RESTful applications. So ClientResource is generally the class to use in order to execute client requests to such applications.

One very interesting feature you should consider with ClientResource is the ability to use annotated interfaces as described below.

public interface MyRestfulService {
    @GET
    Contact getContact(String id);
}

Now how to use the interface:

ClientResource cr = new ClientResource("http://...");
MyRestfulService service = cr.wrap(MyRestfulService.class);
Contact contact = service.getContact("id");

As you can see, everything is now hidden to you (conversion, conneg...).

Hope it helps you. Thierry