Another good option is JBoss RESTEasy . In addition to implementing the JAX-RS 2.0 Client standard (ie it is possible to make calls with the same code as @utluiz demonstrated for Jersey), the library has its own proxies-based API.
Sample 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 susceptible to errors).
For a design Open Source / article that I am writing together with a colleague, we have decided to code a method that upload images to Facebook on the POST with multipart / form-data encode) and compare with the code of a specialized library RestFB ). You can see the difference in size and complexity of the publicarRestFB
vs publicarGraphAPI
to feel the drama.