Call another rest api from my server in Spring-Boot

Mahdi picture Mahdi · Feb 21, 2017 · Viewed 170.7k times · Source

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 specific user on an event.

Does Retrofit have any method to achieve this? If not, how I can do that?

Answer

Torsten N. picture Torsten N. · Feb 21, 2017

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