Call another rest api from my server in Spring-Boot

前端 未结 5 1492
北恋
北恋 2020-12-01 01:30

I want to call another web-api from my backend on a specific request of user. For example, I want to call Google FCM send message api to send a message to a

5条回答
  •  隐瞒了意图╮
    2020-12-01 01:46

    This website has some nice examples for using spring's RestTemplate. Here is a code example of how it can work to get a simple object:

    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);
    }
    

提交回复
热议问题