# RestTemplate

# HttpHeaders

@RestController
@RequestMapping("/rest")
public class RestTemplateDemo {

  public String getSomeData() {
    HttpHeaders headers = new HttpHeaders();
    headers.set("X-SOME-KEY", "some-value");
    HttpEntity<String> entity = new HttpEntity<>(headers);

    RestTemplate restTemplate = new RestTemplate();
    String url = "https://api.domain.com/some-path";
    ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
    return response.getBody();
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15