EasyApiProxy.WebApi 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasyApiProxy.WebApi --version 1.0.5                
NuGet\Install-Package EasyApiProxy.WebApi -Version 1.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasyApiProxy.WebApi" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyApiProxy.WebApi --version 1.0.5                
#r "nuget: EasyApiProxy.WebApi, 1.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EasyApiProxy.WebApi as a Cake Addin
#addin nuget:?package=EasyApiProxy.WebApi&version=1.0.5

// Install EasyApiProxy.WebApi as a Cake Tool
#tool nuget:?package=EasyApiProxy.WebApi&version=1.0.5                

EasyApiProxy

呼叫範例

    // 建立API 代理物件 可以公用 也必須公用 因為其實做包含一個專用的 HttpClient
    // HttpClinet 微軟官方明確的說必須公用 否則回有tcp/ip資源不足的問題
    var api = new ApiProxyBuilder()
        // 預設的Api Protocol 就是異常錯誤如何封裝的方式
        .UseDefaultApiProtocol("http://localhost:8081/api/Demo")
        .Build<IDemoApi>();

    // 呼叫Api
    var ret = await api.Login(new Login { Account = "david", Password = "123" });

Api 介面定義

    public interface IDemoApi
    {
        Task<AccountInfo> Login(Login req);

        Task Logout(TokenInfo req);

        Task<string> GetEmail(TokenInfo req);

        string GetServerInfo();

        [ApiMethod(Name = "RunProc_001")]
        Task<string> RunProc(ProcInfo info);
    }

後台實作範例

    /// <summary>
    /// backendapi
    /// </summary>
    [DefaultApiResult]
    [RoutePrefix("api/Demo")]
    public partial class DemoApiController : ApiController, IDemoApi
    {
        [Route("Login"), HttpPost]
        public async Task<AccountInfo> Login(Login req)
        {
            await Task.Delay(1000);
            if (req.Account == "david" && req.Password == "123")
            {
                return new AccountInfo { Account = req.Account, Token = "123456789", Expired = DateTime.Now.AddHours(1) };
            }
            throw new NotImplementedException();
        }

        [Route("Logout"), HttpPost]
        public async Task Logout(TokenInfo req)
        {
            await Task.Delay(1000);
            if (req.Token == "123456789")
                return;
            throw new ApplicationException("The Token Not exits");
        }

        [Route("GetEmail"), HttpPost]
        public async Task<string> GetEmail(TokenInfo req)
        {
            await Task.Delay(1000);
            if (req.Token == "123456789")
            {
                return "david@gmail.com";
            }
            throw new ApplicationException("The Token Not exits");
        }

        [Route("GetServerInfo"), HttpPost]
        public string GetServerInfo()
        {
            return "Demo Server";
        }
    }
Product Compatible and additional computed target framework versions.
.NET Framework net451 is compatible.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1 104 8/27/2024
3.0.0 96 8/27/2024
2.1.0 119 8/14/2024
2.0.0 109 8/12/2024
1.0.8 92 8/8/2024
1.0.6 96 8/7/2024
1.0.5 85 8/6/2024
1.0.4 85 8/6/2024
1.0.0 95 8/6/2024