# RestClient **Repository Path**: xianyu_087/RestClient ## Basic Information - **Project Name**: RestClient - **Description**: 基于springboot的http资源请求工具 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2018-06-23 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # RestClient #### 项目介绍 基于springboot的声明式http资源请求工具 #### 安装教程 1. mvn install #### 使用说明 1. 引入依赖 ```xml com.xianyu.open rest-client 1.0.0-RELEASE ``` 2. springboot启动类添加 @EnableRestClient ```java @SpringBootApplication @EnableRestClient public class HelloApplication { public static void main(String[] args) { SpringApplication.run(HelloApplication.class, args); } } ``` 3. 声明接口规则,规则与springMvc一致 RestClient注解的value值为serverUrl,可配置也可硬编码,配置部分使用${}接收数据, GetMapping/PostMapping/PutMapping等同理,配置接口url ```java @RestClient("${test.server}") public interface HelloRestClient { @GetMapping("${test.restUrl}/{name}/{age}") Map getTest2(@PathVariable("name") String name, @PathVariable("age") String age,@RequestParam Map map); } ``` 4. 配置 ```yaml # restclient配置项,目前只支持连接超时配置 xianyu: restClient: # 默认5000 connect-timeout: 2000 # 默认5000 read-timeout: 3000 # 配置url,针对调用第三方系统的开发、测试、生产环境配置不同的url,主要配置serverUrl test: server: http://localhost:8080 restUrl: /get ``` 5. 异常 异常完整类名:com.xianyu.open.restclient.exception.RestClientException; 异常信息:RestClientExceptionModel,此模型就三个属性: url: 发出的url地址; responseEntity:相应信息 relException:原异常