-
-
Save heidsoft/ef2c39d827c01efa203d01256f41449a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.spring.aws.gateway.controller; | |
| import org.springframework.beans.factory.annotation.Qualifier; | |
| import org.springframework.http.HttpEntity; | |
| import org.springframework.http.HttpHeaders; | |
| import org.springframework.http.HttpMethod; | |
| import org.springframework.http.ResponseEntity; | |
| import org.springframework.web.bind.annotation.GetMapping; | |
| import org.springframework.web.bind.annotation.PathVariable; | |
| import org.springframework.web.bind.annotation.RequestMapping; | |
| import org.springframework.web.bind.annotation.RestController; | |
| import org.springframework.web.client.RestTemplate; | |
| /** | |
| * Created on 12/January/2021 By Author Eresh, Gorantla | |
| **/ | |
| @RestController | |
| @RequestMapping("/api") | |
| public class SampleController { | |
| final RestTemplate awsRestTemplate; | |
| final RestTemplate restTemplate; | |
| public SampleController(@Qualifier("awsRestTemplate") RestTemplate awsRestTemplate, RestTemplate restTemplate) { | |
| this.awsRestTemplate = awsRestTemplate; | |
| this.restTemplate = restTemplate; | |
| } | |
| @GetMapping("/pets") | |
| public ResponseEntity<Object> testMethod() { | |
| String result = awsRestTemplate.getForObject("<url>", String.class); | |
| return ResponseEntity.ok(result); | |
| } | |
| @GetMapping("/pets/{id}") | |
| public ResponseEntity<Object> testMethod1(@PathVariable Integer id) { | |
| HttpHeaders headers = new HttpHeaders(); | |
| headers.set("x-api-key", "<api-key>"); | |
| HttpEntity request = new HttpEntity(headers); | |
| ResponseEntity<String> responseEntity = restTemplate.exchange("<url>"+id, | |
| HttpMethod.GET, request, String.class); | |
| String result = responseEntity.getBody(); | |
| return ResponseEntity.ok(result); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment