在Spring-Boot中从我的服务器调用另一个rest api [英] Call another rest api from my server in Spring-Boot

查看:345
本文介绍了在Spring-Boot中从我的服务器调用另一个rest api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据用户的特定请求从后端调用另一个Web-api.例如,我想调用 Google FCM 发送消息api,以将消息发送给特定事件的特定用户.

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?

推荐答案

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

这篇关于在Spring-Boot中从我的服务器调用另一个rest api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆