Skip to content

Latest commit

 

History

History
61 lines (49 loc) · 1.99 KB

README.en.md

File metadata and controls

61 lines (49 loc) · 1.99 KB

WebApiClient

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.

1 Nuget

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

2. Http(s) request

2.1 Interface declaration

[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; }
}

2.2 Call request

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. Documents

4. Features