# Forest **Repository Path**: bruce6213/forest ## Basic Information - **Project Name**: Forest - **Description**: Forest是一个极简的轻量级HTTP调用API框架,让Java发送HTTP/HTTPS请求不再难; 它比OkHttp和HttpClient更高层,比Feign更轻量,是封装调用第三方restful api client接口的好帮手。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-06 - **Last Updated**: 2024-12-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 定义 ``` Forest是一个极简的轻量级HTTP调用API框架,让Java发送HTTP/HTTPS请求不再难; 它比OkHttp和HttpClient更高层,比Feign更轻量,是封装调用第三方restful api client接口的好帮手。 ``` # [官方地址](https://forest.dtflyx.com/) # 与SpringBoot 集成 ## 引入依赖 ``` com.dtflys.forest forest-spring-boot-starter 1.5.33 ``` ## 配置文件 > ``` > forest: > bean-id: config0 # 在spring上下文中bean的id, 默认值为forestConfiguration > backend: okhttp3 # 后端HTTP API: okhttp3 【支持`okhttp3`/`httpclient`】 > max-connections: 1000 # 连接池最大连接数,默认值为500 > max-route-connections: 500 # 每个路由的最大连接数,默认值为500 > timeout: 3000 # 请求超时时间,单位为毫秒, 默认值为3000 > connect-timeout: 3000 # 连接超时时间,单位为毫秒, 默认值为2000 > retry-count: 0 # 请求失败后重试次数,默认为0次不重试 > ssl-protocol: SSLv3 # 单向验证的HTTPS的默认SSL协议,默认为SSLv3 > logEnabled: true # 打开或关闭日志,默认为true > ``` ## 配置扫描接口 ![image-20241206104950744](https://gitee.com/bruce6213/image/raw/master/image-20241206104950744.png) ## 构建请求接口 ``` public interface Client { @Get(url = "http://172.31.16.41:28081/zhsh/thirdParty/Xinjiang/getDeviceLocation/{deviceId}") Result getRealTimeLocation(@Var("deviceId") String deviceId); @Post( url = "http://172.31.16.41:28081/zhsh/thirdParty/Xinjiang/getUserInfo", headers = {"Content-Type: application/json"} ) Result getUserInfo(@Body("number") String number); } ``` ## 测试验证 ``` @Autowired private Client client; @Test void contextLoads() { Result realTimeLocation = client.getRealTimeLocation("861959069933710"); System.out.println(realTimeLocation); Result userInfo = client.getUserInfo("00002"); System.out.println(userInfo); } ```