Using Spring Rest Client


Add Maven Dependency :

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>

Sending Object Using Post request:

RestTemplate temp = new RestTemplate();
temp.postForLocation(“http://localhost:8181/hr/add”, employee);

Retreive List of Objects Using Post Request

RestTemplate temp = new RestTemplate();
List<Employee> employees = Arrays.asList(temp.postForObject(“http://localhost:8181/hr/data”, MediaType.APPLICATION_JSON, Employee[].class));