resttemplate get rest api call in java

Solutions on MaxInterview for resttemplate get rest api call in java by the best coders in the world

showing results for - "resttemplate get rest api call in java"
Lyam
01 Oct 2019
1private static void getEmployees()
2{
3    final String uri = "http://localhost:8080/springrestexample/employees";
4 
5    //TODO: Autowire the RestTemplate in all the examples
6    RestTemplate restTemplate = new RestTemplate();
7 
8    String result = restTemplate.getForObject(uri, String.class);
9    System.out.println(result);
10}
11
Emanuele
07 Aug 2019
1private static void getEmployees()
2{
3    final String uri = "http://localhost:8080/springrestexample/employees";
4    RestTemplate restTemplate = new RestTemplate();
5     
6    EmployeeListVO result = restTemplate.getForObject(uri, EmployeeListVO.class);
7     
8    //Use the response
9}
10
Alessandra
06 Jan 2019
1@Autowired
2CloseableHttpClient httpClient;
3 
4@Bean
5public RestTemplate restTemplate() {
6 
7    RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory());
8    return restTemplate;
9}
10 
11@Bean
12public HttpComponentsClientHttpRequestFactory clientHttpRequestFactory() {
13 
14    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory 
15                            = new HttpComponentsClientHttpRequestFactory();
16    clientHttpRequestFactory.setHttpClient(httpClient);
17    return clientHttpRequestFactory;
18}
19
Monica
30 Jan 2021
1@Bean
2public RestTemplate restTemplate(RestTemplateBuilder builder) {
3 
4    return builder
5            .setConnectTimeout(Duration.ofMillis(3000))
6            .setReadTimeout(Duration.ofMillis(3000))
7            .build();
8}
9