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

查看:44
本文介绍了在 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.

Retrofit 是否有任何方法可以实现这一目标?如果没有,我该怎么做?

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

推荐答案

这个网站有一些使用 spring 的 RestTemplate 的很好的例子.下面是一个如何获取简单对象的代码示例:

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天全站免登陆