Simplest Possible REST Client

To access the Simplest Possible REST Endpoint from Java, you will have to implement some code:


  final String URI = "http://localhost:8080/hello-rest/resources/message";
        Client client = ClientBuilder.newClient();
        String result =
        assertThat(result, containsString("duke"));

For server-to-server communication no additional dependency is required. If you are using the client as test driver, you will have to declare the dependency to the SPI of you choice e.g.


See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home:



String result = Unirest.get("http://localhost:8080/hello-rest/resources/message"). asString();


Posted by Urb on May 11, 2016 at 11:29 AM CEST #

Unirest's API is nice, but not much better:

String result = Unirest.get("http://localhost:8080/hello-rest/resources/message"). asString();


String result = ClientBuilder.newClient().target("http://localhost:8080/hello-rest/resources/message").request().get(String.class);

I like to rely on Java EE dependencies whenever possible when deploying to an application server. Unirest and its transitive dependencies add about 2MB to the WAR. Whether or not that 2MB is justified depends on the project, but as Adam Bien has pointed out (, the smaller the WAR, the faster the deploy.

Posted by David on May 11, 2016 at 06:46 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments