Coder Social home page Coder Social logo

madeinchinalmc / webapiclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnetcore/webapiclient

0.0 1.0 0.0 5.43 MB

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

License: MIT License

C# 99.94% Batchfile 0.06%

webapiclient's Introduction

WebApiClient                    

1 Nuget包

WebApiClient.JIT

PM> install-package WebApiClient.JIT
  • 可以在项目中直接引用WebApiClient.JIT.dll就能使用;
  • 不适用于不支持JIT技术的平台(IOS、UWP);
  • 接口要求为public;

WebApiClient.AOT

PM> install-package WebApiClient.AOT
  • 项目必须使用nuget安装WebApiClient.AOT才能正常使用;
  • 没有JIT,支持的平台广泛;
  • 接口不要求为public,可以嵌套在类里面;

2. Http请求

接口的声明

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

接口的调用

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. Wiki文档

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

4. 联系方式

  1. 加Q群439800853 注明WeApiClient
  2. 邮箱[email protected],不重要的尽量不要发

webapiclient's People

Contributors

bao2314483 avatar elderjames avatar fossabot avatar xljiulang avatar

Watchers

 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.