RestTemplate is the REST client in the Spring framework and commonly used for RESTful communication


Create a new RestTemplate like this

RestTemplate restTemplate = new RestTemplate();

Make a GET request and receive the response as a String

ResponseEntity<String> response = restTemplate.getForEntity("http://localhost:8080", String.class);

{"id":1,"content":"Hello World!"}

Deserialization of the response to pojo's is easily done with the jackson dependencies

ResponseEntity<Greeting> response2 = restTemplate.getForEntity("http://localhost:8080", Greeting.class);
Greeting pojo = response2.getBody();

Hello World!

Of cource it's possible to POST, PUT and use the other HTTP methods, as well as handling HTTP Headers

HttpEntity<Greeting> entity = new HttpEntity<Greeting>(new Greeting());
entity.getHeaders().add("Connection", "keep-alive");"http://localhost:8080", HttpMethod.POST, entity, Void.class);

Here are the Maven dependencies you need to use Spring as the client library for your load tests

<!-- -->

<!-- -->

Copyright © All Rights Reserved