Cover by Bill Burke

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

RESTEasy Client Framework

RESTEasy[16] is the JBoss (Red Hat) JAX-RS implementation. As with java.net.HttpURLConnection and Apache HTTP Client, it provides a programmatic API to submit HTTP requests with the additional feature of it being JAX-RS-aware. To use the API, you create org.jboss.resteasy.client.ClientRequest objects. You build up the request using the following constructor and methods:

public class ClientRequest {
   public ClientRequest(String uriTemplate) {}

   public ClientRequest followRedirects(boolean follow) {}
   public ClientRequest accept(String accept) {}
   public ClientRequest formParameter(String parameterName,
                                        Object value) {}
   public ClientRequest queryParameter(String parameterName,
                                         Object value) {}
   public ClientRequest matrixParameter(String parameterName,
                                           Object value) {}
   public ClientRequest header(String headerName, Object value) {}
   public ClientRequest cookie(String cookieName, Object value) {}
   public ClientRequest cookie(Cookie cookie) {}
   public ClientRequest pathParameter(String parameterName,
                                         Object value)
   public ClientRequest body(String contentType, Object data) {}
...
}

The ClientRequest constructor can take any expression you put in an @Path annotation, but it must also have scheme, host, and port information. Here’s an example of building up a GET request:

ClientRequest request =
                 new ClientRequest("http://example.com/customers/{id}");
request.accept("application/xml")
       .pathParameter("id", 333);

We allocate the ClientRequest instance, passing in a URL template. ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required