Skip to content

Instantly share code, notes, and snippets.

@j-tim
Created July 12, 2019 12:38
Show Gist options
  • Save j-tim/6d0ce8177ae5f7551cd75bf078d7abc1 to your computer and use it in GitHub Desktop.
Save j-tim/6d0ce8177ae5f7551cd75bf078d7abc1 to your computer and use it in GitHub Desktop.
Create a RestTemplate instance myself.
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