使用Spring Boot获得REST API的GET / POST Requst

维杰什:

我有一个REST服务和一个外部服务器,https://api.myrestservice.com并且我有一个Spring Boot Application在本地运行http://localhost:8080现在,我想使用本地运行的Spring Boot App(即通过)向REST API地址发出GETPOST请求,即https://api.myrestservice.com/users获取所有用户http://localhost:8080/users我没有得到如何将本地应用程序请求重定向到外部服务器请求。

Jitesh Shivnani:

希望我能正确回答你的问题。您正在尝试获取本地应用,以从服务器上运行的应用获取数据。

您可以在spring boot应用程序中使用以下示例代码。

private void getUsers() {

     final String uri = "https://api.myrestservice.com/users";
     RestTemplate restTemplate = new RestTemplate();
     Users result = restTemplate.getForObject(uri, Users.class);      
     System.out.println(result); 
}

然后,您的getUsers可以由您的spring boot应用程序中的getUsers Controller调用。

如果您想查看更多示例,添加参考-https: //howtodoinjava.com/spring-restful/spring-restful-client-resttemplate-example/

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

POST方法中的HTTP Requst从一种服务到另一种服务+ SpringBoot REST API

具有oneToMany关系的Spring Boot Rest API Post方法

spring-boot REST POST API发送文件

在执行POST请求并读取用户使用Spring Boot Rest API输入的POST数据时进行JSON模式验证

使用 spring restTemplate 对 POST REST API 进行身份验证

使用Spring Boot的Post API返回嵌套json的空值

REST API-为什么使用PUT DELETE POST GET?

使用 JSON、REST、Spring Boot JAVA POST 数据

使用LDAP认证的Spring Boot REST API

使用Rest API 404的Spring Boot

使用 java 和 spring boot 的 REST api

在Spring Boot应用程序中,只有Post REST api有效,PUT,GET,DELETE api不起作用

Requst中的空用户代理在易用的API中创建NPE

从Angular到Spring Rest API的POST请求

如何使用Spring Boot和Spring Security保护REST API?

$ http.post()使用AngularJS使用Spring REST API时未添加值

Azure 函数 REST API 处理 GET POST

Spring Boot CRUD REST API + Spring Data JPA + H2 DB:在测试中获得 NPE 而不是在 Postman

对NodeJS的React可以POST到Spring Boot REST API,但不能放入相同的API-CORS问题

如何使用 InvokeHttp 来 Rest Api(POST)

POST REST API使用参数调用函数

REST API使用post自动生成值

Spring REST中如何根據職責使用GET和POST方法

无法在 Spring-boot 中使用自签名 https 验证来自 Postman 的 POST/GET 请求方法

可以对get和post rest api使用相同的资源名称吗

Delphi REST GET但不支持POST与AusPost eParcel API一起使用

使用file_get_contents的Rest POST API在PHP中不起作用

使用Spring Boot / Spring Security配置公共端点仅适用于GET,不适用于POST

在Spring Boot中使用REST API时出错