Created
July 12, 2019 12:38
-
-
Save j-tim/6d0ce8177ae5f7551cd75bf078d7abc1 to your computer and use it in GitHub Desktop.
Create a RestTemplate instance myself.
This file contains 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 io.stockgeeks.hello.world.api; | |
import lombok.extern.slf4j.Slf4j; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
import org.springframework.web.client.RestTemplate; | |
@RestController | |
@Slf4j | |
public class HelloWorldController { | |
private RestTemplate restTemplate = new RestTemplate(); | |
@GetMapping("/api/hello") | |
public Greeting sayHello() { | |
log.info("Received call on /api/hello. And will call /api/random-name on the random-name-service!"); | |
RandomName randomName = restTemplate.getForObject("http://localhost:8081/api/random-name", RandomName.class); | |
log.info("Received response from random-name-service: {}", randomName); | |
return new Greeting("Hello World: " + randomName.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment