Giter Site home page Giter Site logo

blueteethyl1986 / webapiclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnetcore/webapiclient

0.0 1.0 0.0 5.09 MB

一款基于HttpClient封装,只需要定义c#接口并修饰相关特性,即可异步调用远程http接口的客户端库

License: MIT License

C# 99.93% Batchfile 0.07%

webapiclient's Introduction

WebApiClient                     English

WebApiClient.JIT将替代旧的Laojiu.WebApiClient,在运行时使用Emit创建Http请求接口的代理类;
WebApiClient.AOT支持包括需要AOT的平台,在编译时插入Http请求接口的代理类IL指令到输出的程序集;

1 Nuget包

PM> install-package WebApiClient.JIT
支持 .net framework4.5 netstandard1.3 netcoreapp2.1

PM> install-package WebApiClient.AOT
支持 .net framework4.5 netstandard1.3 netcoreapp2.1

2. Http(s)请求

2.1 接口的声明

[HttpHost("http://www.webapiclient.com")] 
public interface IMyWebApi : IHttpApi
{
    // 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; }
}

2.2 接口的调用

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. 功能特性

  • 面向切面编程方式
  • 内置丰富的接口、方法和参数特性,支持使用自定义特性
  • 适应个性化需求的多个DataAnnotations特性
  • 灵活的ApiAcitonFilter、GobalFilter和IParameterable
  • 支持与外部HttpMessageHandler实例无缝衔接
  • 独一无二的请求异常条件重试(Retry)和异常处理(Handle)链式语法功能

4. 详细文档

5. 联系方式

6. 功能视图

功能脑图

webapiclient's People

Contributors

xljiulang avatar elderjames avatar fossabot avatar bao2314483 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.