2017-02-21 43 views
8

我想從用戶的特定請求的後端調用另一個web-api。 舉例我想打電話給google FCM發送消息api發送消息給特定用戶的一個事件。在Spring-Boot中從我的服務器調用另一個休息api

改裝有什麼辦法可以達到這個目的嗎?或者如果不是我能做到的話?

+0

你並不需要一個第三方庫。春天已經有['RestTemplate'](http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html) –

+0

好吧,讓我知道我如何使用休息模板? – Kenji

+0

做一些研究。這非常簡單。 –

回答

9

This website has some nice examples for using spring's RestTemplate. 這裏是它如何工作,得到一個簡單的對象的代碼示例:

private static void getEmployees() 
{ 
    final String uri = "http://localhost:8080/springrestexample/employees.xml"; 

    RestTemplate restTemplate = new RestTemplate(); 
    String result = restTemplate.getForObject(uri, String.class); 

    System.out.println(result); 
}