1. Nuget
PM> install-package Laojiu.WebApiClient
支持 .net framework4.5
netcoreapp2.0
netstandard2.0
[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; }
}
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);
}
- 天生支持的面向切面编程方式
- 内置丰富的接口、方法和属性特性,支持使用自定义特性
- 适应个性化需求的多个DataAnnotations特性
- 灵活的ApiAcitonFilter、GobalFilter和IParameterable
- 支持与外部HttpMessageHandler实例无缝衔接
- 独一无二的请求异常条件重试和异常处理链式语法功能
- 加群439800853 注明WeApiClient
- 366193849@qq.com,不重要的尽量不要发