WebApiClient.JIT
PM> install-package WebApiClient.JIT
- 不适用于不支持JIT技术的平台(IOS、UWP);
- Http接口声明要求为public;
WebApiClient.AOT
PM> install-package WebApiClient.AOT
- 适用于不支持JIT技术的平台(IOS、UWP);
- Http接口声明不要求为public,可以嵌套在类里面;
接口的声明
public interface IUserApi : IHttpApi
{
// GET api/user?account=laojiu
// Return json或xml内容
[HttpGet("api/user")]
ITask<UserInfo> GetAsync(string account);
// POST api/user
// Body Account=laojiu&password=123456
// Return json或xml内容
[HttpPost("api/user")]
ITask<boo> AddAsync([FormContent] UserInfo user);
}
接口的配置
HttpApi.Register<IUserApi>().ConfigureHttpApiConfig(c =>
{
c.HttpHost = new Uri("http://www.webapiclient.com/");
c.FormatOptions.DateTimeFormat = DateTimeFormats.ISO8601_WithMillisecond;
});;
接口的调用
var api = HttpApi.Resolve<IUserApi>();
var user = new UserInfo { Account = "laojiu", Password = "123456" };
var user1 = await api.GetAsync("laojiu");
var state = await api.AddAsync(user);
相对于v0.3.6或以前版本,Api有如下变化
HttpApiClient.Create()-> HttpApi.Create()HttpApiFactory.Add()-> HttpApi.Register()HttpApiFactory.Create()-> HttpApi.Resolve()TimeoutUrlAttributeDebugAttribute
-
加Q群825135345 注明WeApiClient
-
邮箱[email protected],不重要的尽量不要发
ddd ddd ddd ddd ddd ddd