anon
anon

Reputation: 4192

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

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.

Upvotes: 0

Views: 782

Answers (1)

Thierry Templier
Thierry Templier

Reputation: 202286

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

Upvotes: 2

Related Questions