Search code examples
spring-bootspring-dataretrofit

Call another rest api from my server in Spring-Boot


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?


Solution

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