WebApiClient.JIT will replace the old Laojiu.WebApiClient, and use Emit to create the proxy class of http request interface at runtime.
WebApiClient.AOT supports all platforms, including the platform that requires AOT, inserting proxy class IL instructions from http request interface to output assembly at compile time.
PM> install-package WebApiClient.JIT
supports .net framework4.5 netstandard1.3 netcoreapp2.1
PM> install-package WebApiClient.AOT
supports .net framework4.5 netstandard1.3 netcoreapp2.1
[HttpHost("http://www.webapiclient.com")]
public interface IMyWebApi : IHttpApi
{
// GET webapi/user?account=laojiu
// Return original string
[HttpGet("/webapi/user")]
ITask<string> GetUserByAccountAsync(string account);
// POST webapi/user
// Body Account=laojiu&password=123456
// Return json or xml content
[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);
}