Last active
May 22, 2019 12:57
-
-
Save donchan922/349ec3aa3313d5c0df845004c6b65d7c to your computer and use it in GitHub Desktop.
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
@SpringBootApplication | |
public class DemoApplication implements CommandLineRunner { | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApplication.class, args); | |
} | |
private final RestTemplate restTemplate; | |
// RestTemplateをコンストラクタインジェクションする | |
public DemoApplication(RestTemplate restTemplate) { | |
this.restTemplate = restTemplate; | |
} | |
@Override | |
public void run(String... args) { | |
// REST APIにGETでリクエストする | |
// 第一引数:URL、第二引数:レスポンスの型 | |
Quote response = restTemplate.getForObject("https://gturnquist-quoters.cfapps.io/api/random", Quote.class); | |
System.out.println(response.toString()); // Quote{type='success', value=Value{id=1, quote='Working with Spring Boot is like pair-programming with the Spring developers.'}} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment