Professional Documents
Culture Documents
Consuming REST APIs With RESTEasy Client
Consuming REST APIs With RESTEasy Client
Client
https://howtodoinjava.com/resteasy/resteasy-client-for-consuming-rest-apis/
So far in this blog, we have been learning about building RESTful webservices which are
server side components. In this post, we will learn to build a RESTful client for consuming
the webservices written in previous posts.
I will be re-using the code base written for RESTEasy + JAXB xml example.
@GET
@Path("/users/{id}")
user.setId(id);
user.setFirstName("demo");
user.setLastName("user");
return user;
@POST
@Path("/users")
//Some code
To build a RESTful client using client capabilities of JAX-RS RESTEasy, follow given
instruction.
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>2.3.1.GA</version>
</dependency>
<dependency>
<groupId>net.sf.scannotation</groupId>
<artifactId>scannotation</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>2.3.1.GA</version>
</dependency>
request.accept("application/xml");
if(response.getResponseStatus().getStatusCode() != 200)
{
}
System.out.println(user.getId());
System.out.println(user.getFirstName());
System.out.println(user.getLastName());
user.setId(100);
user.setFirstName("Lokesh");
user.setLastName("Gupta");
jaxbMarshaller.marshal(user, writer);
//Set the accept header to tell the accepted response format
request.body("application/xml", writer.getBuffer().toString());
if(response.getResponseStatus().getStatusCode() != 201)
{
}
Happy Learning !!