Another good option is the Resteasy of Jboss. In addition to implementing the JAX-RS 2.0 Client standard (i.e., it is possible to make calls with the same code @utluiz demonstrated for Jersey), the library has its own API based on proxies.
Example of documentation:
Client client = ClientFactory.newClient();
WebTarget target = client.target("http://example.com/base/uri");
ResteasyWebTarget rtarget = (ResteasyWebTarget)target;
SimpleClient simple = rtarget.proxy(SimpleClient.class);
client.putBasic("hello world");
Where SimpleClient
is an annotated interface (can be even the same as the server):
public interface SimpleClient {
@PUT
@Path("basic")
@Consumes("text/plain")
void putBasic(String body);
// ... Demais métodos
}
Some other options besides the Jersey and Resteasy
Finally, while this is not necessarily practical, you can always use raw HTTP Apis to consume REST services. Httpurlconnection, Apache Httpclient, etc. This gives you more control in exchange for much more extensive code (and error-prone).
To a little project Open Source / article I’m writing along with a colleague, we decided to encode a method that makes upload of images for Facebook in the nail (POST with Encounter Multipart/form-date) and compare with the code of a specialized library (Restfb). You can see the difference in size and complexity of methods publicarRestFB
vs publicarGraphAPI
to feel the drama.
Just linking to client documentation and remembering that for the client only the
jersey-client
and optionally a Connector (guide for the Maven). In innocence, in a situation a few times ago, we did a lambança in theClasspath
trying to set up the client, whereas the App Server already makes available all that was needed through a Shared library (hidden but existing) :D.– Anthony Accioly