Motivation

Create support for Http headers in getForEntity to allow simpler code. Currently if one needs to add headers in a GET call one would have to use restTemplate.exchange() which is verbose and could different from coding convention of using restTemplate.postForEntity(), etc.

Use

HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth("abcd);
ResponseEntity<Object> res = restTemplate.getForEntity(url , headers, Object.class);

Comment From: pivotal-cla

@kooixh Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@kooixh Thank you for signing the Contributor License Agreement!

Comment From: rstoyanchev

Thanks for the suggestion but we don't want to add even more methods to RestTemplate. We would also have to add the same for other HTTP methods, and that's not sustainable. This is why in 6.1 we're adding a new RestClient on the same infrastructure but with a fluent API. In the mean time, you can use the exchange method with a RequestEntity:

RequestEntity<Void> requestEntity = RequestEntity
        .get(url)
        .headers(headers -> headers.setBearerAuth("abcd"))
        .build();

ResponseEntity<String> response = 
        new RestTemplate().exchange(requestEntity, String.class);