消费Restful的web服务(三)
构架工程
创建一个springboot工程,去消费RESTFUL的服务。这个服务是 http:///gturnquist-quoters.cfapps.io/api/random ,它会随机返回Json字符串。
在Spring项目中,它提供了一个非常简便的类,叫RestTemplate,它可以很简便的消费服务。
消费服务
通过RestTemplate消费服务,需要先context中注册一个RestTemplate bean。代码如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
@Bean public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } @Bean public CommandLineRunner run(RestTemplate restTemplate) throws Exception { return args -> { String quote = restTemplate.getForObject( "http://gturnquist-quoters.cfapps.io/api/random", String.class); log.info(quote.toString()); }; } |
|
1
|
运行程序,控制台打印: |
|
1
|
{ “type”: “success”, “value”: { “id”: 6, “quote”: “It embraces convention over configuration, providing an experience on par with frameworks that excel at early stage development, such as Ruby on Rails.” } } |

消费Restful的web服务(三)的更多相关文章
- Spring Boot教程(三)消费Restful的web服务
构架工程 创建一个springboot工程,去消费RESTFUL的服务.这个服务是 http:///gturnquist-quoters.cfapps.io/api/random ,它会随机返回Jso ...
- Python flask 基于 Flask 提供 RESTful Web 服务
转载自 http://python.jobbole.com/87118/ 什么是 REST REST 全称是 Representational State Transfer,翻译成中文是『表现层状态转 ...
- 使用ASP.NET web API创建REST服务(三)
本文档来源于:http://www.cnblogs.com/madyina/p/3390773.html Creating a REST service using ASP.NET Web API A ...
- 常见的三种Web服务架构
常见的三种Web服务架构 转自http://www.cnblogs.com/bvbook/archive/2008/12/24/1360942.html 相互竞争的服务架构 The Competing ...
- 用 Java 技术创建 RESTful Web 服务--转载
简介 JAX-RS (JSR-311) 是为 Java EE 环境下的 RESTful 服务能力提供的一种规范.它能提供对传统的基于 SOAP 的 Web 服务的一种可行替代. 在本文中,了解 JAX ...
- Springboot & Mybatis 构建restful 服务三
Springboot & Mybatis 构建restful 服务三 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务二 2 restful ...
- <转>用 Java 技术创建 RESTful Web 服务
转自:https://www.ibm.com/developerworks/cn/web/wa-jaxrs/#N1017E JAX-RS:一种更为简单.可移植性更好的替代方式 Dustin Amrhe ...
- RESTful Web服务的操作
1.首先我们说一下Http协议是无状态的 HTTP协议是无状态的,我们看到查到的用到的返回404,500,200,201,202,301.这些不是HTTP协议的状态码. 是HTTP的状态码,就是HTT ...
- RESTful Web 服务:教程
RESTful Web 服务:教程 随着 REST 成为大多数 Web 和 Mobile 应用的默认选择,势必要对它的基本原理有所了解. 在它提出十多年后的今天,REST 已经成为最重要的 Web ...
随机推荐
- 每日质量NPM包模态框_react-modal
一.react-modal 官方定义: Accessible modal dialog component for React.JS 理解: 一个容易使用的React模态框组件 二.用法 有时候我们不 ...
- Vue运行报错--eslint
Errors:? 1? http://eslint.org/docs/rules/no-trailing-spacesYou may use special comments to disable s ...
- _itemmod_hidden
该表中的物品放在背包或银行中中会计算属性 `entry`物品ID `comment` 备注
- codeforces gym 100947 J. Killing everything dp+二分
J. Killing everything time limit per test 4 seconds memory limit per test 64 megabytes input standar ...
- Qt532.【转】Qt创建鼠标右键菜单
ZC:可以通过 设置 (QWebView*)->setContextMenuPolicy(NoContextMenu); 来关闭 QWebView的默认右键菜单 Qt创建鼠标右键菜单_疯华正茂 ...
- [原][粒子特效][spark]粒子系统system、主节点group、渲染器render
深入浅出spark粒子特效连接:https://www.cnblogs.com/lyggqm/p/9956344.html system: A class defining a complete sy ...
- linux下源码安装
●源码的安装(./configure –prefix 命令用法)一般由3个步骤组成:配置(configure).编译(make).安装(make install). Configure是一个可执行脚本 ...
- java重新学习记载的一些资料。
1.ided的注册码地址. IDEA的密码:http://idea.lanyus.com/ 2.
- python float转为decimal
73.2413793103 ======= 73.2414 <type 'float'> ======= <class 'decimal.Decimal'> 当断言这两个值相等 ...
- Github的简易操作
一.初涉Github 1.github官网:https://github.com/ 2.三步走完成账号的创建 3.进入Github主页,选择[Create a repository](创建一个仓库用来 ...