WebApiClient.AOT.dll 调用api地址 -> 调用方法
2024-08-25 17:54:30
优点:简化api调用过程,WebApiClient.AOT.dll中的IHttpApi接口
缺点:只适用于内部服务之间的调用(没有验证过程)
1.继承IHttpAPi接口
public interface IService: IHttpApi
{
[HttpGet("api/getvalue/{id}")]
Task<ValueModel> GetValue([PathQuery]Guid id); [HttpGet("api/getallvalue")]
Task<ValueModel[]> GetValues();
}
2.在startup中注入
services.AddSingleton(serviceProvider => HttpApiClient.Create<IService>(serviceProvider.GetRequiredService<ApiConfig>()));
3.在ApiConfig配置api地址
public class ApiConfig : HttpApiConfig
{
public ApiConfig(IConfiguration configuration, ILoggerFactory loggingFactory)
{
var httpHost = configuration["apiurl"];//apiurl在配置文件中
HttpHost = new Uri(httpHost);
}
}
然后,就可以使用IService.GetValue(id)调用api/getvalue/{id}
最新文章
- October 26th Week 44th Wednesday 2016
- Struts2 自定义MVC框架
- oracle 11g ORA-12541: TNS: 无监听程序 (DBD ERROR: OCIServerAttach)
- LeetCode Find Peak Element
- HashPasswordForStoringInConfigFile 已过时
- H5离线缓存机制-manifest
- contos 安装jdk1.8
- 【5】python核心编程 第八章-条件和循环
- uva140
- [POJ2823]Sliding Window 滑动窗口(单调队列)
- 使用re开发python计算器
- Android开发 ViewConfiguration 用法
- Netty学习记录
- ll(ls -l) 列属性
- 【转】WPF自定义控件与样式(3)-TextBox &; RichTextBox &; PasswordBox样式、水印、Label标签、功能扩展
- Django后端项目----restful framework 认证源码流程
- sprint初步计划(第一天)
- iOS开发网络篇—Socket编程
- Layui 好用的弹出框
- jq实现 元素显示后 点击页面的任何位置除元素本身外 隐藏元素