Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

An open source project based on the HttpClient. You only need to define the c# interface and modify the related features to invoke the client library of the remote http interface asynchronously.

License

Notifications You must be signed in to change notification settings

MineCodeLife/WebApiClient

Open more actions menu
 
 

Repository files navigation

WebApiClient                    

1 Nuget包

WebApiClient.JIT

PM> install-package WebApiClient.JIT
  • 不适用于不支持JIT技术的平台(IOS、UWP);
  • Http接口声明要求为public;

WebApiClient.AOT

PM> install-package WebApiClient.AOT
  • 适用于不支持JIT技术的平台(IOS、UWP);
  • Http接口声明不要求为public,可以嵌套在类里面;

2. Http请求

接口的声明

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);

3. Api变化

相对于v0.3.6或以前版本,Api有如下变化

  • HttpApiClient.Create() -> HttpApi.Create()
  • HttpApiFactory.Add() -> HttpApi.Register()
  • HttpApiFactory.Create() -> HttpApi.Resolve()
  • Timeout
  • UrlAttribute
  • DebugAttribute

4. Wiki文档

  1. WebApiClient基础
  2. WebApiClient进阶
  3. WebApiClient高级
  4. WebApiClient.Extensions
  5. WebApiClient.Tools.Swagger

5. 联系方式

  1. 加Q群825135345 注明WeApiClient
  2. 邮箱366193849@qq.com,不重要的尽量不要发

About

An open source project based on the HttpClient. You only need to define the c# interface and modify the related features to invoke the client library of the remote http interface asynchronously.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.5%
  • Other 0.5%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.