WebApiClient

An open source project based on the HttpClient. You only need to define the c# interface and modify the related features to invoke the client library of the remote http interface asynchronously.

MIT License

Stars
2K
Committers
16

Bot releases are hidden (Show)

WebApiClient - Latest Release

Published by xljiulang 5 months ago

WebApiClient -

Published by xljiulang about 2 years ago

  • ApiParameterContext的ParameterValue属性增加Set方法;
  • WebApiClientCore.Extensions.SourceGenerator修复运行时方法信息与代理类的方法信息可能错乱的问题
WebApiClient - Core_2.0.2

Published by xljiulang over 3 years ago

  • 增加全局接口配置的功能;
  • 修复一些bug
WebApiClient - Core_2.0.1

Published by xljiulang over 3 years ago

  • 更变:网络请求异常也执行Filter;
  • 更变:ApiReturnAttribute当Content-Type为null时无条件成功匹配;
  • 修正:FormDataFile中文文件名的支持;
  • 新增:LoggingFilterAttribute增加虚的WriteLog方法;
  • 新增:TokenProviderFactory的Create()方法使用缓存;
  • 新增:CustomValueReturnAttribute和DefaultValueReturnAttribute抽象类;
WebApiClient -

Published by xljiulang over 3 years ago

  • 增加IApiAttribute接口,强化语法智能分析;
  • 增加IDataCollecction接口,ApiRequestContext的Properties属性类DataCollecctionod类型变成IDataCollecction接口;
  • 各Attribute的代码逻辑优化;
WebApiClient -

Published by xljiulang over 3 years ago

由于部分类型所在程序集已经变化,从1.x版本更新过来需要项目和项目依赖的包的WebApiClient和WebApiClient.Extensions都同时升级。

抽象与实现完全分离

  • 接口与抽象类已放到新的WebApiClientCore.Abstractions程序集
  • ApiActionDescriptor变成抽象类,增加IApiActionDescriptorProvider接口
  • ApiActionInvoker设计为抽象类,增加IApiActionInvokerProvider接口
  • ApiRequestContext等Context类不包含任何方法,之前的方法将放到WebApiClientCore程序集扩展出来
  • 增加IHttpApiActivator接口,为代理类生成和实例创建方式提供可切换的实现

增强的语法分析

  • 重构了WebApiClientCore.Analyzers,严谨的null检查;
  • 减少不必要的重复执行代码逻辑块,获得更快的语法分析;
  • 不需要显式为接口继承IHttpApi也能获得语法分析;

新增和增强的功能

  • 增加IApiFilter类型,HttpApiOptions增加GlobalFilters的全局过滤器集合;
  • 新增IWebApiClientBuilder IServiceCollection.AddWebApiClient()扩展,用于后续全局配置的扩展;
  • 新增IWebApiClientBuilder IWebApiClientBuilder.UseJsonFirstApiActionDescriptor()扩展,缺省参数特性使用[JsonContent];
  • 新增IWebApiClientBuilder IWebApiClientBuilder.UseSourceGeneratorHttpApiActivator()扩展,使用SourceGenerator编译时生成代理类代码;
  • 在不配置HttpHost的情况下,[HttpGet(path)]现已支持带path参数;
  • UriAttribute参数特性已经变成全能型,现已支持与[HttpGet(path)]等带path或者不带path结合使用;
  • JsonContent类型增加JsonContent(object?, JsonSerializerOptions?, Encoding?)构造函数;
  • FormContent类型增加FormContent(object?, KeyValueSerializerOptions?)构造函数;
  • Extensions.OAuths删除了内部类型TokenProviderDescriptor,增加TokenProviderService<THttpApi,TTokenProvider>服务来管理TokenProvider;
  • Extensions.OAuths删除了内部类型声明式的IOAuthClientApi接口,由OAuth2Client服务来原生实现请求,避免Extensions.SourceGenerator找不到代理类;

更快的性能和更少的内存分配

  • 增加ValueStringBuilder类型,在多个关键性能的小内存申请,缓冲区由ArrayPool租赁改成stackalloc的ValueStringBuilder;
  • 增加UriValue类型,用于实现连续的Uri参数占位符替换、增加query参数,减少string到Uri的转换;
  • 增加HttpPath类型,[HttpGet]、[HttpPost]等执行时减少1次不必要的string到Uri的转换;
  • Uri参数占位符替换,内存减低至原来的1/3;
  • 创建代理类实例时,从DI获取服务由多次减少为1次;
  • benchmark结果,cpu时间比1.5版本更少、内存分配也更低,post json请求cpu时间和内存分配稳低于Refit的1/3,get和post form时表现更好;

移除的功能

  • HttpApi.Create()方法已经被删除,由DI管理的IHttpApiActivator来创建和激活接口的代理类;
  • 序列化工具相关接口已被删除,增加xxxSerializer等静态序列化类:因为各序列化工具无法统一接口,WebApiClient只关注他们的Options而不是接口;
WebApiClient -

Published by xljiulang almost 4 years ago

WebApiClient -

Published by xljiulang almost 4 years ago

  • 移除GET和HEAD请求设置Content的限制
  • KeyValueSerializer增加支持IEnumerable<KeyValuePair<string, string>> #145
  • KeyValueSerializer序列化数值类型对象时,不再经过Json序列化
  • 增加JsonDateTimeConverter类型,标记JsonLocalDateTimeConverter为过时类型
  • 增加JsonDateTimeAttribute,可直接修饰模型的属性
  • 增加BasicAuthenticationHeaderValue类型
WebApiClient -

Published by xljiulang almost 4 years ago

  • PathQueryAttribute增加SerializeToKeyValues虚方法;
  • WebApiClientCore.Extensions.OAuths兼容abp;
WebApiClient - Core_1.1.2

Published by xljiulang almost 4 years ago

  • 增加AuthorizationHandler和CookieAuthorizationHandler,用于处理身份过期自动刷新场景;
  • 不读取Type的Module属性,以支持.net5的单文件发布应用;
WebApiClient - Core_1.1.1

Published by xljiulang about 4 years ago

  • 增加SpecialReturnAttribute,并作为RawReturnAttribute的基类;
  • 增加NoneReturnAttribute,用于处理204等状态码的无ContentType响应;
  • 重构内部的接口代理类,以支持未来的SourceGenerator代理生成;
WebApiClient - Core_1.1.0

Published by xljiulang about 4 years ago

WebApiClientCore

  • 修复core3.0接口重复注册时"The HttpClient factory already has a registered client with the type"的异常;
  • 增加HttpApi.GetName()和IHttpClientBuilderExtensions的ConfigureHttpApi()多个重载方法;
  • HttpCientContext增加OptionsName属性,方便上层项目的对Options的扩展;

WebApiClientCore.Extensions.OAuths

  • 增加ITokenFactory,用于创建TokenProvider实例;
  • 增加注册自定义TokenProvider的功能,以支持非OAuth的token请求流程;
  • OAuthTokenAttribute支持获取接口的基础接口对应的TokenProvider(多个接口共享TokenTokenProvider);
  • 增加OAuthTokenHandler用于应用token,支持401状态后刷新token并重试请求(服务器token丢失不影响到客户端);

WebApiClientCore.Extensions.NewtonsoftJson

  • 相关Attribute使用HttpCientContext.OptionsName来获取对应的Options值;
WebApiClient -

Published by xljiulang about 4 years ago

  • 提升json反序列化的性能
  • 接口语法不支持,异常由TypeInitializationException改为NotSupportedException
  • 更严谨的null检查
WebApiClient -

Published by xljiulang over 4 years ago

  • 修复当响应的json使用非utf8编码时反序列化的问题
  • 增加过滤掉重复MediaType的IApiReturnAttribute
WebApiClient -

Published by xljiulang over 4 years ago

  • ApiReturnAttribute调整为先验证ContentType匹配之后,再执行其它逻辑(验证响应状态码、设置结果值);
  • 修复nuget包icon消失的问题
WebApiClient -

Published by xljiulang over 4 years ago

  • RequestDelegateBuilder->ContextInvoker
  • 增加xml序列化配置选项
  • netstandard21编译和打包
  • 增加KeyValue序列化键名配置选项
  • 优化提交非utf8的json内容时的数据转码
WebApiClient -

Published by xljiulang almost 5 years ago

增加.net core框架下直接与DI集成。

WebApiClient -

Published by xljiulang almost 5 years ago

在非.net framework下使用Microsoft.Extensions.Caching.Memory替换System.Runtime.Caching

WebApiClient -

Published by xljiulang over 5 years ago

  • AuthTokenFilter请求前后方法支持重写;
  • 增加支持FileInfo做为文件上传参数
  • 增加JsonString`1类型,表示对象的json文本;
WebApiClient -

Published by xljiulang over 5 years ago

  • 增加HttpApi.RegisterFactory()方法
  • 增加ParameterAttribute,满足一般情况易于理解传参的要求
  • 修复使用了CacheAttribute且缓存命中时RequestMessage没有及时dispose的问题
Related Projects