Skip to content

一款基于HttpClient封装,只需要定义c#接口并修饰相关特性,即可异步调用远程http接口的客户端库

License

Notifications You must be signed in to change notification settings

xq546247083/WebApiClient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PM> install-package Laojiu.WebApiClient
支持 .net framework4.5  netcoreapp2.0  netstandard2.0

2. Http(s)请求

2.1 接口的声明

[HttpHost("http://www.webapiclient.com")] 
public interface IMyWebApi : IHttpApiClient
{
    // GET webapi/user?account=laojiu
    // Return 原始string内容
    [HttpGet("/webapi/user")]
    ITask<string> GetUserByAccountAsync(string account);

    // POST webapi/user  
    // Body Account=laojiu&password=123456
    // Return json或xml内容
    [HttpPost("/webapi/user")]
    ITask<UserInfo> UpdateUserWithFormAsync([FormContent] UserInfo user);
}

public class UserInfo
{
    public string Account { get; set; }

    [AliasAs("password")]
    public string Password { get; set; }

    [IgnoreSerialized]
    public string Email { get; set; }
}

2.2 接口的调用

static async Task TestAsync()
{
    var client = HttpApiClient.Create<IMyWebApi>();
    var user = new UserInfo { Account = "laojiu", Password = "123456" }; 
    var user1 = await client.GetUserByAccountAsync("laojiu");
    var user2 = await client.UpdateUserWithFormAsync(user);
}

3. 功能特性

  • 天生支持的面向切面编程方式
  • 内置丰富的接口、方法和属性特性,支持使用自定义特性
  • 适应个性化需求的多个DataAnnotations特性
  • 灵活的ApiAcitonFilter、GobalFilter和IParameterable
  • 支持与外部HttpClientHandler实例无缝衔接
  • 独一无二的请求异常条件重试和异常处理链式语法功能

4. 详细文档

5. 联系方式

  • 加群439800853 注明WeApiClient
  • 366193849@qq.com,不重要的尽量不要发

About

一款基于HttpClient封装,只需要定义c#接口并修饰相关特性,即可异步调用远程http接口的客户端库

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%