Jersey Client API#
Jersey ClientBuilder#
JAX-RS Client API is a designed to allow fluent programming model. To create jersey client follow these steps:
Use
ClientBuilder.newClient()
static method.Use
client.target()
method on above obtained client instance.Get
Invocation.Builder
usingwebTarget.request()
method onWebTarget
instance obtained in second step.Execute
invocationBuilder.get()
,put()
,post()
ordelete()
methods to invoke corresponding REST APIs.
Client client = ClientBuilder.newClient( new ClientConfig().register( LoggingFilter.class ) );
WebTarget webTarget = client.target("http://localhost:8080/rest/jersey").path("employees");
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_XML);
Response response = invocationBuilder.post(Entity.entity(emp, MediaType.APPLICATION_XML));
Results#
JerseyClientApiTest