Giter Site home page Giter Site logo

ipenn / webapiclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnetcore/webapiclient

0.0 1.0 0.0 5.83 MB

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: MIT License

C# 99.52% Batchfile 0.07% PowerShell 0.40%

webapiclient's Introduction

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. 邮箱[email protected],不重要的尽量不要发

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.